godot-ldtk-importer icon indicating copy to clipboard operation
godot-ldtk-importer copied to clipboard

Adding Child Node to Entity in Post Import Script

Open eldyer opened this issue 11 months ago • 1 comments

First of all, thanks for creating this awesome plugin!

I'm trying to do something similar to the example in issue #11: In a post entity import script, some_scene is created. Then a child_node is attached to it. Then some_scene is later attached to entity_layer. In the final import some_scene shows up, but child_node doesn't.

No wonder, as the Docs point out:

Note: If you want a child to be persisted to a PackedScene, you must set owner in addition to calling add_child. This is typically relevant for tool scripts and editor plugins. If add_child is called without setting owner, the newly added Node will not be visible in the scene tree, though it will be visible in the 2D/3D view.

Good. But what's the correct owner here? Whatever I try doesn't work. The OP of #11 suggests to use the parent (or grandparent) of entity_layer, but this neither works for me.

eldyer avatar Dec 14 '24 18:12 eldyer

Have you tried entity_layer.get_parent() to get a reference to some parent node? in my case I am using a node to load levels to the level is a child of 'level manager' so this returns the level manager.

the-simian avatar Jan 27 '25 02:01 the-simian