How do I save a scene to a .tscn Godot file?

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

Is it possible to use the following method to save the game (I know it will be very slow): save the current scene to a .tscn file, and then change the main scene to this scene?

What following method?

SteveSmith | 2023-01-14 15:16

My method:save the current scene to a .tscn file, and then change the main scene to this scene. I can do this in Godot 3.5.1?

roma | 2023-01-14 15:25

Yes, that should be possible.

SteveSmith | 2023-01-14 15:34

Do you know how to do it?

roma | 2023-01-14 15:41

:bust_in_silhouette: Reply From: Satscape

If I’ve understood correctly, you might be looking for the ResourceSaver

It will save any Resource as a tscn file, which should include Scenes I think.
Switching scenes is done with the SceneTree class. it might be what you’re looking for.
But it might be better to save the state of each thing in a scene instead and then you can load the savegame back later re-spawning everything using the saved data.

Here’s an example of how to save and load gamestate

:bust_in_silhouette: Reply From: roma

Відповідь на це питтання є. Треба написати функцію яка буде збирати всі потрібні дані з об’єктів, зберегти в файл SAVE/DAT, а потім завантажити це. Це є в стандартному підручнику Godot про зберігання ігор.