Recurring 'set_wait_time' on a null instance causes the runtime to error out

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Cameron Kilgore
:warning: Old Version Published before Godot 3 was released.

I’m attempting to implement a legal crawl that displays before the game start, and then eventually transition to a StartMenu. I figured this could be done with a Timer object, through a script on the actual LegalCrawl.tscn Panel node. After 7 seconds, transition to the StartMenu.tscn.

Except, that in its current implementation, I am getting an error of Attempt to call function ‘set_wait_time’ in base ‘null instance’ on a null instance when it attempts to make the set_wait_time call (i’ve highlighted the offending LOC with a comment below). My initial presumption is that the Engine isn’t loading the Timer class. This seems like the Class instance for Timer isn’t being loaded. I’m still new to Godot, am I missing something here?

# TransitionToMenu.gd
# Transitions to the Menu Screen Scene

extends Panel

var timer

func _ready():
	"""
	Inherits behavior from Ready Event
	"""
	timer = get_node("Timer")
	timer.set_wait_time(5) # Errors Here: Attempt to call function 'set_wait_time' in base 'null instance' on a null instance.
	timer.connect("timeout", self, "_on_timeout_expire")
	timer.start()

func _on_timeout_expire():
	"""
	This method runs the Scene loading method, tranisitioning to the main
	menu Scene.
	"""
	get_tree().change_scene("res://StartMenu.tscn")
	

Is “Timer” a Timer child of the node “LegalCrawl” ? If you try to add a timer from code, you are missing some steps"

var timer= Timer.new()
add_child(timer)
timer.connect("timeout",self,'_your_function',[variable])
timer.set_wait_time(5)
timer.start()

MrMonk | 2017-04-08 05:10

:bust_in_silhouette: Reply From: avencherus

Most likely the offending line is this one:

timer = get_node("Timer")

My bet would be your path is wrong. You’ll want to make sure there is actually a Timer node as a child of this node with the script.