Making a scene reset itself

Godot Version

4.3

Question

I am making a game kinda like the dino-game on google when you lose internet and I want to add a score / highscore but I cant find a way to reset the scene/node reset itself but not the main scene / root scene so I can keep the score there. I have tried just pasting reload_scene() among other things but I just can’t get something to work.

You can try get_tree().reload_current_scene()

1 Like

Well i don’t want to reset the main scene I want to reset the same scene/node holding the code

You can then store all the variables in the _ready() method and reapply them whenever you want.

var original_position: Vector3
func _ready() -> void:
    original_position = position

func reload() > void:
    position = original_position

Well it needs to be able to update because thats the 1 thing in this case that is not going to be reset

I don’t understand what you mean by that, can you explain?
What’s wrong with the code I suggested?

I am trying to keep a score variable which would change and, from what I understand, the ready function would not be able to continuously update the variable and keep it if I use the get_tree().reload_current_scene() method.

You can keep a score in the Autoload class - see this article to see how it works.

Then you can call get_tree().reload_current_scene() method to reload your scene without removing information about your score.

1 Like

This worked thanks for the help!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.