Signal Priority Question

Godot Version

Godot-4

Question

Hey guys, I am new to godot and gamedev in general, can someone tell me what will happen if within the same script, 2 signals fire at the same time, both affecting a sprite’s animation. Which one will win over the other?

My Scene: a root node2d, “Crow”, an animated Sprite 2d “CrowSprite”, an Area2d
animated sprite has 2 default animations that i am playing randomly every time one of them ends (i set them to non loop) using the animation finished signal.

while the script is looking out for the sprite’s animations to finish, it is also looking out for a player to enter the area2d for it to play the “fly” animation, this is through the body entered signal.

if a body enters at the same time the animation finishes, which will play? the default animations, or the fly animation?

here is my code, thank you for your time.

extends Node2D

func _ready():
var time = randi() % 2 #random time to start the animation
await(get_tree().create_timer(time).timeout) #wait for the random time
$CrowSprite.play(“default”)

func _process(_delta):
pass

func _on_area_2d_body_entered(body):
if body.name == “Player”:
fly_away()

func fly_away():
$Area2D.set_deferred(“monitoring”,false)
$CrowSprite.play(“fly”)
var tween:= create_tween()
tween.set_trans(Tween.TRANS_QUINT).set_ease(Tween.EASE_OUT)
tween.tween_property(self, “position”, Vector2(self.position.x + 500, self.position.y - 100), 5)
tween.finished.connect(despawn)

func despawn():
queue_free()

func _on_crow_sprite_animation_finished():
if ($CrowSprite.animation == “default” or $CrowSprite.animation == “default2”) and $CrowSprite.animation != “fly”:
var random_animation = randi() % 2
if random_animation == 0:
$CrowSprite.play(“default”)
else:
$CrowSprite.play(“default2”)