[SOLVED] adding a child at ready(): or work around

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Asoth

I want to expand a node_A (adding child) from a script attached to this node_A :
Ok I know it is not possible to do it directly but I cannot understand or make work any suggestion found on the net.

call_deferred produce nothing
request_ready():, I got no clue where to put it

func _ready():
var position= Position3D.new()

the most upsetting thing is that print_tree_pretty print exactly what I want to do. but nothing appear on the right panel

when I use this
print_tree does not even show any added child

In which context are you doing this? Is it in game or in editor with tool script?

Zylann | 2018-08-10 12:45

it is actually a code that worked properly as a tool script.
I want to make it do what he is supposed to do on “play” instead of “run”.
and splitting my code into each node instead of putting everything on one big tool script sound less cumbersome.
(i want to create the whole hierarchy of node by script)

Asoth | 2018-08-10 20:51

There is almost no difference between tool and game though. tool just means the node runs in game AND editor. call_deferred("add_child",position) should have worked. When I test your code it works as well, it prints this:


Zylann | 2018-08-10 20:55

well, the “posi” node show up when printed but do not show up in the inspector, at least for me.

Asoth | 2018-08-11 02:31

wait what is the heck with the “remote scene tree” is it actually normal nothing appear in the inspector when I add node from the script while running ?

Asoth | 2018-08-11 09:05

:bust_in_silhouette: Reply From: Asoth

Sounds like I was just unaware of the existence of remote inspector over local one.
I will investigate what it is. is it mentioned somewhere I overlooked in the doc ?
I would be surprised to be only one to struggle with that.

When you run the game, it runs in a separate process. What the editor shows you is the scene as it is in the resources of your game. If you want to see the scene as it is WHILE you play the game, use the remote scene tree tab in the editor. It’s not turned on automatically because it’s not needed often, and as a debugging tool it takes a small hit on performance.
Are you coming from Unity by any chance?

Zylann | 2018-08-11 12:40

thank so much you for clarification,
I am not really coming from unity , just tried few hours on unity and discovered that godot exist, so I came to godot.

Asoth | 2018-08-11 22:35