Instantiate separately exported scene at runtime

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Enrique Ávila Rodríg

Hello,

For my project I need to have a standalone executable that has all the base functionality and be capable of loading extra assets at runtime:

Say in main.tscn I have a base node capable of loading a scene (say dlc1.tscn) and instantiate it as a child.

· I want to export the main.tscn without the dlc1.tscn as main.exe.
· Afterwards export dlc1.tscn as dlc1.pck (or any other way)
· Now when I run main.exe it loads the dlc1 scene even though it couldn’t before the second export.

This is the code I have in the main.tscn at the moment (not working)

	var scene = load("res://dlc1.tscn")
	if (scene != null):
		var scene_instance = scene.instance()
		scene_instance.set_name("dlc1")
		add_child(scene_instance)

Is this even possible?

Thanks in advance!

:bust_in_silhouette: Reply From: MysteryGM

· I want to export the main.tscn without the dlc1.tscn as main.exe.

Check that dlc1.tscn is no longer parented when exporting. You can just remove the child.:

$dlc1.tscn.queue_free() #this should work

Afterwards export dlc1.tscn as dlc1.pck (or any other way)

Just export it, you can find it in the file system. Check this part of the document for a rough explanation: Resources — Godot Engine (3.0) documentation in English

· Now when I run main.exe it loads the dlc1 scene even though it couldn’t before the second export.

Godot keeps the data for objects etc in the .TSCN file, if you do not remove it before exporting then it will be saved in there.