![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Jaspev |
I have a global singleton script that I’m trying to call to a timer in. That timer is in another scene (that isn’t my main scene). In this global singleton script, I want a function that uses this timer. The scene that has the timer that I want is called “World”. The global singleton script is just called “Global”.
I found this post from 2017 and they had the same issue I have, but I cannot get any of the examples from the top answer on that post to work on my project.
This is my code (in my global script):
onready var AttackTimer = get_tree().get_root().get_node("/root/World/TimerAttack")
func stopattacktimer():
AttackTimer.stop()
AttackTimer.wait_time = 0.1
AttackTimer.start()
I’ve also tried
onready var AttackTimer = get_tree().get_root().get_node("/root/Global/TimerAttack")
and
onready var AttackTimer = get_node("TimerAttack")
When running all of these, they always return “Attempt to call function ‘stop’ in base ‘null instance’ on a null instance”.
I know I can right click a node and copy it’s node path but it just copies the name of the node for me.
Does it’s path depend on the file system path?
If so, the file path to the scene with the timer I want is res://scenes/World.tscn
The file path to the global singleton is res://scripts/Singletons/Global.gd
I hope someone can help, thank you for reading.
Edit: I don’t know if this is important, but when I copy the node path of the parent scene of the Timer I want to call to, it says the node path is just “.” and I was wondering if that’s normal? Also when I type “get_node(” in my global script, the only auto fill answer is “/root/Global”. And when I run the game and go to the point where I would want to run the function, and I look at the scene structure, I can see World right next to Global, but it just is not recognizing World as a node.
img of scene structure when running the game