Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | GameVisitor |
Hi all,
get_current_scene() is returning null when called in _ready(): method as below:
extends WorldEnvironment
func _ready():
var sceneTree = get_tree() //value returned is not null here
var curScene = sceneTree.get_current_scene() //null !?!
Shouldn’t the node be initialized here, and a proper value returned ?
(WorldEnvironment is my scene root node and the script is attached to it)
Thanks.
Does it happen if you use Play Scene (F6)?
Is this scene your main scene?
hilfazer | 2018-12-22 13:59
Works fine for me.
How did you know that curScene
is null? I don’t see any output here.
P! | 2018-12-22 21:51
@hilfazer, That’s interesting !
When hitting F6, it does have a value, when running the project it doesn’t…
Which brings us to your second suggestion: no, it is a scene loaded using deferred loading as per official documentation.
Maybe this _ready() is being called upon reaching : current_scene = s.instance()
but for the call get_current_scene()
to be successful get_tree().set_current_scene( current_scene )
needs to execute first.
Any idea how to bypass this ? (without changing goto_scene()
method since it is used for all scene loading).
Thx for your suggestion so far !
GameVisitor | 2018-12-22 22:06
@P! in the debugger it shows as null, the issue is as suspected by @hilfazer, something to do the way the scene is loaded and added to the project.
GameVisitor | 2018-12-22 22:11