How to get a scene name

Godot Version

4.7

Question

Does anyone know how to check what the root node of a scene is via code? For context, I need my enemy ship to check which scene it’s in, and the one im using is definitely wrong, since it crashed instantly.

Thanks! I’m pretty new to Godot, so that’s why i may ask dumb questions. :sweat_smile:

extends Area2D

@export var platforner_hard_enemy_texture: Sprite2D

@onready var owner_name = owner.name


func _ready() -> void:
	print(owner_name)


func _process(delta: float) -> void:
	pass

Post your scene structure.

this will crash if the scene you’re running has this script on the root node - because it has no owner, and as a resultowner will be null

thanks, that’s the issue. the enemy ship’s a scene of its own. any way of getting the scene name tho?

Can you explain the greater why? This sounds like an XY problem.

Assuming this script is attached to the root node, you could get the scene file name from property .scene_file_path, but if you just want the node’s name then use property .name

thanks dude