0 votes

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?

in Engine by (44 points)

1 Answer

+1 vote

Your intentions are not possible.


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

by (4,972 points)

Can I initialize another scene in a script?


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

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

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()

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.