How to get a node from another scene that has not been initialized?

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

I have a scene with a script. It needs to get a node from another scene that has not been initialized. I cannot initialize that scene because it has sprites and I don’t want the window to be filled with superfluous sprites. I can’t autoload that scene because then the sprites are viewable. I need that node to be made on command though and no node paths seems to work because the scene hasn’t been initialized. How do I do this?

:bust_in_silhouette: Reply From: Wakatta

Your intentions are not possible.


initialize that scene while its set to be hidden or hide/show it as needed

Can I initialize another scene in a script?

John97 | 2021-04-17 01:07


var packed_scene = load("path_to_scene.tscn")
var node = packed_scene.instance()
add_child(node) #add to sceneTree

You can manipulate the node scene without adding it to the sceneTree

Wakatta | 2021-04-17 01:47

But won’t have a node path until added to the sceneTree so can only be manipulated using the node var

Wakatta | 2021-04-17 01:49

I always seem to get the error: Invalid call. Nonexistent function ‘instance’ in base ‘Nil’.
I’m completely sure I didn’t misspell anything and it seems to happen regardless of the scene I try to load.

It seems to work only when I write
var content = preload(path).instance()

John97 | 2021-04-17 02:27

Okay, I’ve kind of figured it out now.

John97 | 2021-04-17 03:27