Can’t create a child of a prefab

I previously posted this in “How do I…” but I have a feeling this might be a bug

TL;DR - I can’t dynamically create prefab’s children outside the “onCreate” methods.

Here’s the original post:

I’ve been playing around with custom objects in gdevelop and here’s a custom action i created:


Here’s how it looks on the inside:

It takes in 3 parameters, a player object that I want to create, a hatId used to create a hat object (which is a child of “Player” custom object) and color tint to colorize the player’s sprite.
After it processes everything it calls another function called “createSelectedHat” to use all this data and customize the player

And everything seems to be working except for the hat object creation. It just isn’t getting created, but the color tint changes for some reason. What’s the cause of this?

It seems that if a “global” function calls a “player” function it can’t create player’s children?

And here’s the thing, when I call “createSelectedHat” from “onCreated” method
or when I create a player object in my scene events sheet and then use createSelectedHat in the same event it works just fine? The hat gets created. But it isn’t exactly what I was looking for.

Project download

1 Like

I was playing around with it. If I started with a prefab object without any children then when I added children objects at runtime, the objects didn’t show. But, if the prefab already had any child object added through the designer then the created children objects were visible.

The child objects were added. I verified the object count by adding an expression to the return the number of the children object. It increased when I added the child at runtime but I could only see the object if an object already existed beforehand.