For the life of me, I cannot figure out why, during run-time, it’s complaining that “despawn_timer” is null.
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var timer: Timer = $Timer
@onready var despawn_timer: Timer = %Despawn
signal walking
signal finished_walking
func _ready():
if npc_data:
apply_data()
current_state = STATE.IDLE
sprite.play("idle")
timer.start() #THIS IS FINE
#BUT THIS--WTF
despawn_timer.set_wait_time(randi_range(30, 120))
despawn_timer.start()
I haven’t written anything in GDScript yet, but the only difference I can see in what you’ve shown is how you refer to the timers - one reference starts with $, the other with %. I don’t know how they work in GDScript though and what’s the difference.
The Sprite, which I gather also works, because you’re not complaining about it, also uses $.
If it’s not that, then it has to be a setting in the property inspector. Compare those between the two timers.
And kudos for making a minimum reproducible example!
First thing I would do is try it without the scene unique identifier.
If this script is the NPC script it should work (as unique) UNLESS the NPC or the unique node is not part of the scene. Remember that scene unique is only valid in the current scene.
A scene unique node can only be retrieved by a node inside the same scene.
Otherwise make sure the line you are pointing out is the one that is error-ing.
I have never felt the need for scene unique node naming. I always find other methods of exposing child nodes. (But this is neither here nor there)