Godot Version
v4.3.stable.official [77dcf97d8]
Question
`Hello there,
new dev here.
Im trying to change an animation on receiving a signal. Heres my code for connecting to the signal and my attempt on changing the animation and a label text:
extends Control
@onready var animated_sprite_2d: AnimatedSprite2D = $ColorRect/ColorRect/AnimatedSprite2D
@onready var effect_label_rect: ColorRect = $EffectLabelRect
@onready var effect_label: Label = $EffectLabelRect/EffectLabel
func _ready() -> void:
Global.effects_updated.connect(_on_effects_updated)
_on_effects_updated
#animated_sprite_2d.animation = "Defense" #works
func _on_effects_updated():
print("Effects updated in Effect Box called")
var index = -1
index = Global.active_effects.find("Defense")
if index != -1:
print(name)
print("Found effect Defense")
animated_sprite_2d.animation = "Defense"
effect_label.text = "Defense"
When the effect is updated, everything gets printed, but the animations and the effect label wont change. I have tried changing them in the on_ready function and it works, but it wont when the signal function is called.
Im stuck, any help would be appreciated.
Thanks,
Ben
`