add scene node to another scene in code

:bust_in_silhouette: Reply From: Stupido

First you need to understand that everything is a node.
The “Scene” itself is a node. The “Player”, too.

So what you are looking for is to add a node to an other node as a child.
So more like spawning.

var myNode = preload("Drag and Drop type your path here")

func add_myNode _to_my_game(): 
     var myNode _instance =  myNode .instance() 
     get_tree().get_root().add_child(myNode_instance)

     #set position if needed
     myNode_instance.global_transform = global_transform

Thats how you can add a node to the “furthest up” node via script for example.

Thanks for answering so quick, it should work.

Bot7 | 2021-03-17 11:36

How can i set the position ?

GammerSly | 2021-03-18 14:56

myNode_instance.translation = Vector3(0, 0, 0)

I think that should work

Bot7 | 2021-03-18 20:42

Thank you

Bot7

GammerSly | 2021-03-21 16:51