Topic was automatically imported from the old Question2Answer platform.
Asked By
StewardLines
I made a 2D rpg game. This main node starts as the title screen which changes the scene to level 1 upon pressing start.
In summary there are three levels that the player goes through. When the player dies and goes to the main menu, I want all the changes of the levels the player went through to be reset. Restarting the values of Globals/Singletons are not issue, however, the changes within each levels need to be reset.
For example things move to a different position based on conditions.
I am thinking of resetting manually, but I was wondering if anyone has any recommendations or insights on other ways to do it.
When a level is loaded and before any changes happen to it, save it as a packed scene.
You can use this scene next time the player dies and has to restart the level.
Here is how you save a scene as a packed scene:
var packed_scene = PackedScene.new()
packed_scene.pack(get_tree().get_current_scene())
ResourceSaver.save("res://my_packed_scene.tscn", packed_scene)
It works thank you!
Also anyone else using Godot 4 they switched it backwards with ResourceSaver.
It is this instead
var packed_scene = PackedScene.new()
packed_scene.pack(get_tree().get_current_scene())
ResourceSaver.save(packed_scene,“res://my_packed_scene.tscn”)