This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

i need help on a way to store the current root node of my levels so that my gameover screen (which is a seperate scene) can restart which ever level the player is in.

my gameover script

    extends Control

func onButtonpressed():
get
tree().change_scene("res://Scenes/WorldManager.tscn")

my player script (the part which calls in the gameover scene)

    if health <=0:
    get_tree().change_scene("res://Scenes/Deathscreen.tscn")

level 1 and 2's node hierachy
https://imgur.com/a/XB8S2Bs

in Engine by (20 points)

1 Answer

0 votes
Best answer

You need to add an AutoLoad (i.e. a script that isn't replaced when you change the current scene), store the path of the current level there and then reload that path on gameover. Let's say your AutoLoad is accessible as a Singleton called Global:

# include this in the scripts of your level scenes
func _ready():
    Global.current_level = self.filename

# include this in the script of your deathscreen
get_tree().change_scene(Global.current_level)
by (10,634 points)
selected by
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.