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

Hello, I am trying to make a scene where, when the enemy "catches" the player, they go to a "chance screen" and if they survive, they return to the previous scene.

I have tried using gettree().geteditedsceneroot.filename and keep getting "nil" errors. What's a best practice for this? my scene changes are handling fine except for this one.

I am trying to use a global variable to store the scene using my door class in each room. I only have three rooms loaded at any one time so I don't need a complex level-change system.

Singleton ## hold current scene if in kill_screen

var sceneJar = preload("res://assets/TESTROOM_00.tscn")


Then the "update" in each room, running at ready:

func room_store():
    _currentRoom = get_tree().get_current_scene().get_name()
    Global.sceneJar = _currentRoom


Then the "kill screen" function that should reload that room but fails to do so, because i keep getting errors: (which i don't get, because i use this method with everything else) Note: my Global variable IS updated at the ready here.

func _ready():
       _escape_dest = Global.sceneJar

func escape():
    var _free = load(_escape_dest)
    var _free_me = get_tree().change_scene_to(_free)


I keep getting Resource not found errors but the filepaths it is showing are accurate. What is happening? Why does this method work for everything and not this? It's loading the path, getting the data, it's just not connecting the scenes.

Also: sorry if this question is common. I searched and kept finding deprecated answers.

in Engine by (562 points)

1 Answer

+1 vote
Best answer

Your problem is likely that get_name() doesn't return what you think it does. If you print that out, you'll see it's just the node's unique name (like Area2D or Line2D). That's not a valid value for loading a scene from the file system.

Depending on the details, I'm guessing you probably want the value of the filename property instead.

So, this:

 _currentRoom = get_tree().get_current_scene().filename
by (22,704 points)
selected by

I was trying this method, was having some trouble with it but maybe it was my syntax. I will give it a go!

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.