Godot Version
4.2.1
Question
I have a scene that has 3 children. These are Timers. They are added to the script using @onready var Timer1 = $Timer1. This scene was instantiated as a child scene of another scene. When I start the game, the following error appears:
count_up_timer.gd _ready(): Node not found: “TImer1” (relative to “/root/Overworld”)
Why can’t it find the Timers?
The node with count_up_timer.gd
is looking for its child named Timer1
If it isn’t a child, you can use get_node("path/to/Timer1")
. If it is the timer, you can just use those same methods on itself (i.e. simply get_node()
instead of Timer1.get_node()
If you describe the layout of your tree, I might be able to help you find a better way to connect the timer.
Is it correct like this?
@onready var Timer1 = get_node(“CountUpTimer/Timer1”)
I can’t tell without more information.
The specific problem is that the node named “Timer1” isn’t found, relative to the script’s Node. Can you tell me about the tree of your game, specifically where CountUpTimer and Timer1 are located? Also, what Node is this script on?
Is the screenshot sufficient?
Yes, I see what’s going on now. The path name should be:
@onready var Slot1_Timer = get_node(“TimerSlot1”)
That’s because the current node is CountUpTimer. “CountUpTimer/TimerSlot1” means to first look for a child named CountUpTimer, then a child of that, to TimerSlot1.
Ah, and I also see, class_name
must go above extends Node2D
. It has to be the very first thing in the script, other than a possible file annotation.
Please let me know if these two things fixed it!
I’ll test it in a few hours.
In Germany, it is currently 5:15 am. xD
1 Like
I have now placed the class_name at the beginning of the code, and I have adjusted the path to the timers. Unfortunately, I’m still getting an error.
In the parent where I added the scene as an instantiated child scene, I’m accessing it using extends CountUpTimer.
Oh! I think I found the problem. See at the bottom, where it says "relative to /root/Overworld"
? I think that you might have accidentally attached this script to that node, too. Can you double-check that the only Node this script is attached to is, in fact, the CountUpTimer
?