![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | rredesigns |
![]() |
Old Version | Published before Godot 3 was released. |
Hello everyone.
I am trying to add a bunch of nodes I create at runtime, but I can’t get it to work. I know this is a duplicate question, but all the methods I found here and elsewhere didn’t work, furthermore, the get_edited_scene_root() method returns Nil.
So here’s what I tried so far, following the suggestions from this Q&A page:
-
Create a new node: var newNode = Spatial.new()
-
Get the current scene root to add it there: var scene =
get_tree().get_edited_scene_root() -
Add the child: scene.add_child(newNode)
-
Set owner: newNode.set_owner(scene)
It doesn’t matter if I set the owner before or after adding the child, it just doesn’t work. As you might have guessed I am working in the 3D editor, but that shouldn’t make a difference I hope.
Since get_tree().get_edited_scene_root() returns Nil, I have tried some other ways with no luck, like get_tree().get_root().get_child(0) and get_tree().get_current_scene()
What are your thoughts about this? btw, I’m using Godot 2.1.3.
I think adding nodes to the editor tree might only be possible via making a plugin (and then following the procedure you described).
mollusca | 2017-06-06 17:39
The problem lies in the line
scene = gettree().geteditedsceneroot()
Not sure what node you want to add the spatial to. If it the same node the script is on leave it out and just use “add_child(newNode)” and it will add it as a child of the node the script is attached to.
D | 2017-06-06 18:04
Well, I saw in other question that getting the current scene like that was best to add children to the scene root. And the person that asked the question said that was a solution and worked for him.
So I figured I would try it the same way.
rredesigns | 2017-06-09 01:28