0 votes

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.

Godot version 4.0
in Engine by (15 points)

1 Answer

0 votes
Best answer

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)
by (2,017 points)
selected by

It works thank you!

Also anyone else using Godot 4 they switched it backwards with ResourceSaver.
It is this instead

var packedscene = PackedScene.new()
packed
scene.pack(gettree().getcurrentscene())
ResourceSaver.save(packed
scene,"res://mypackedscene.tscn")

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.