0 votes

I’m trying to make a load screen that in a nutshell has a 5-second cooldown, at the end of the cooldown changes the scene.

    # Remove the current level
    var level = get_node("res://game.tscn")
    root.remove_child(level)
    root.level.call_deferred("free")

# Add the next level
    var next_level_resource = load("res://game.tscn")
    var next_level = next_level_resource.instance()
    root.add_child(next_level)

This got me on another post, but it doesn’t work, tells:

"The identifier "root" isn’t declared in the current scope."

I don’t know if it matters that I’m making 2D game.

PS: are the first days I use Godot ;)

Godot version latest
in Engine by (12 points)

1 Answer

0 votes

Hi,
root isnt availabe in a node. You have to get the root node via:

var root = get_tree().get_root()
# or
var root = get_node("/root")

have a look here for more informations:
https://docs.godotengine.org/en/stable/getting_started/step_by_step/scene_tree.html?highlight=get_root

by (3,940 points)
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 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 webmaster@godotengine.org with your username.