How to change owner to the root node?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mateusak
:warning: Old Version Published before Godot 3 was released.

I tried set_owner(get_node("/root/Node2D")) and every other way I know about. Didn’t work. What can I do?

:bust_in_silhouette: Reply From: Aaron

When you say root node, do you mean the current scene’s root or the root ViewPort node?

And are you trying to set the node’s owner specifically, or are you trying to set the node’s parent? Those two are independent and when the scene is loaded a node’s owner is initially set to the scene root.

Also, if you’re going to use get_node("/root/Node2D") make sure Node2D is the actual name of a node in your scene. The path “/root/Node2D” would suggest that Node2D is the name of the root scene node.

In any case, if you want the root ViewPort node you can call get_tree().get_root(). I don’t know the best way to get the scene root node, but get_tree().get_root().get_child(0)will work.

Look, I want to make a node a child of Node2D. That’s all. How do I do it?

mateusak | 2016-08-24 15:54

You don’t mean Node2D the class do you? What does your overall scene structure look like?

To make a node a child of another node you use the method Node.add_child.

Aaron | 2016-08-24 20:26