+4 votes

Hi,
is there a way to get the current scene name?
Thanks.
-J

in Engine by (1,469 points)

1 Answer

+4 votes
Best answer
get_tree().get_current_scene().get_name()
by (701 points)
selected by

is there any reason that calling this would return null instance? i mean there's always a scene.. yet that's what im getting.

var context = get_tree().get_current_scene().get_name()

If your node is not in the tree (not a child of anything), then get_tree will be null and the expression will throw a NullRef error

Thank you for your comment! But when I try it it doesn't give me the name of the scene but the name of the node...

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.