Godot Version
Godot 4.3
Question
Hey!
I just made a new Global variable, but my animationplayer suddently stopped working!
This is the error message:
E 0:00:01:0781 score.gd:13 @ _process(): Node not found: “AnimationPlayer” (relative to “/root/Score”).
<C++ Error> Method/function failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1792 @ get_node()
score.gd:13 @ _process()
extends Label
var score = 0
# Called when the node enters the scene tree for the first time.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
self.text = str(score)
set_process(false)
await get_tree().create_timer(1).timeout
$AnimationPlayer.play("score")
score += 1
set_process(true)
AnimationPlayer.play(“score”) doesnt work for some reason
This is my node tree^
extends Sprite2D
func _ready():
show()
func _process(delta):
if Score.score == 10:
print(Score.score)
hide()
this is the script that calles the other global variable.
Maybe you have accidentally attached the script to the scene root. Notice the error says “relative to ‘/root/Score’” where is that Score node? Not “Scorelabel”. Is it an Autoload?
So this script is score.gd, attached to Scorelabel and an Autoload?
When a script .gd
is made to an Autoload Godot will create a base Node and add it to the scene /root
with the script attached. For you this means it doesn’t have any children (including AnimationPlayer) and it’s type is wrong.
I believe you want to create a separate .tscn
Scene out of your Scorelabel and autoload that .tscn
file, which will instantiate the whole scene adding it to the /root
. You may have to change layer settings like z-index.
1 Like
Hello. I don’t know much about this but You can use a Global :
Create a New Script in main folder and name it Global (you can name it anything but Global is a better choice)
Then use it
you don’t have to use Animation to show score.
if you wanna more information. just write a word
well i do,
its the frame but animated so it pops when you get extra score.
I need it, please dont tell me what i dont need to do.
But thx for your answer!
1 Like