To my beginner understanding, in order to use a scene saved on the drive, one must first use ResourceLoader.load()
to load the scene to acquire a PackedScene
, then instantiate it using PackedScene.instance()
to acquire the Node
that can be finally added as a child.
Following this principle, one can easily export a script String
variable and use it to set which scene will be loaded by a node - even with convenient hints like this:
export(String, FILE, "*.tscn") var scene_path
But that's not fully descriptive in my opinion. I want to select a scene - an only scene - in that exported variable. Looking around the internet, this Godot Q&A post mentions one can export a PackedScene
variable like any other to link to another scene. So I immediately thought of this:
export(PackedScene) var new_scene = null
This looks much cleaner - especially the ability to initialize it to null
, as well as having access to methods like can_instance()
to catch any accidental false inputs in the editor... however, this looks like there is one important link of the chain I mentioned at the start missing. In the end, I'm still selecting the PackedScene
as a path on disk, so when does the load()
happen?
Is this a valid and correct use of the export
keyword, or could this come back to haunt me later if I overuse it?