Open scene from saved file

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

I want to save the current scene to a .dat file, then load and open it when needed. Currently, I’m saving get_tree().current_scene to the file, but I can’t find a way to get the scene from that.

Edit: I’ve found a workaround, which is just to save the root node’s path. I know that it won’t work if the scene and root node have different names, but it works for now. I’d still like to know if there’s a better way to do it, which is likely.

:bust_in_silhouette: Reply From: Merlin1846

Try instancing it as a child of another node. Like this.

-root
–Scene you want to load

-root will manage the instancing but nothing else.

And if you don’t know how to instance, hears an example.

var scene = preload(“res://exampleScene.tscn”).instance()
add_child(scene)

sorry, if your loading from user. then try user:// instead of res:// I think that’s right. And if you use .dat then replaceing the .tscn with .dat should work.

Merlin1846 | 2020-11-17 19:10