system
1
system
4
|
|
|
|
Reply From: |
vnen |
You have to set the new node’s owner as the scene root. When you save a scene the editor saves the root node itself and every node it owns.
my_node.set_owner(scene_root)
I tried this:
mesh_instance.set_owner(get_tree().get_root())
but it produces an error:
ERROR: Node::is_editable_instance: Condition ' !is_a_parent_of(p_node) ' is true. returned: false
At: scene\main\node.cpp:1441
Zylann | 2016-08-13 20:43
It should be the root of the scene, not the root Viewport. Something lilke:
mesh_instance.set_owner(get_tree().get_edited_scene_root())
Is this valid on runtime / exported game?
I guess it should be like this, I guess:
if get_tree().is_editor_hint():
mesh_instance.set_owner(get_tree().get_edited_scene_root())
Zylann | 2016-08-13 21:38
The editor hint check is needed, I think. You can use get_tree().get_current_scene()
in the game.
Actually I think in game there is no need to declare an owner because it’s just like instancing any node.
Zylann | 2016-08-14 02:17