How do I parent an object to another using events

Hello People,

I’m wondering how I can make an object a child of another game objects using the events system.
Is there an action that I have missed

In case you mean by “parent” to pin an object to an other and make the pinned object keep relative position and rotation to “parent” object, there is no built-in solution in GDevelop.

The easiest way to do something like that is, create a custom point for the parent object and set the child object position to be at the point and also update it rotation along with the parent. But this is very limited since you need to know where the child objects going to be pinned exactly, which objects and how many of them.

Example:
parenting_point.zip (38.3 KB)
In case you want to be a bit more flexible, you need to use Math expressions to calculate the relative position and rotation of the child objects. I have tried long time ago but I’m not very good with math, this is the best I was able to come up with:

Example:
parenting_math.zip (27.2 KB)
Not perfect at all, but a lot more flexible than using points. You can use any number of child object in any position and rotation. the only limitation, as it stands you can not have more then one parent object in the scene but only one and the child objects once pinned to the parent object the local position and rotation of the child can not be changed any more, all the child going to keep it relative position and rotation to parent . In case you are good with math, maybe you can improve it and share it :slight_smile:

You can also use the “Object association” extension to be able to have multiple “parent” objects on the scene. However, this extensions only provides a way to link the object virtually (just a way to remember which object is linked to which object). You’ll still need to change the position of the child to keep it on the parent object.