Hi,

I have a function that is supposed to be called when an animation finishes. It gets called 90+% of the time, but sometimes the function isn't called after the animation is done. The animation always plays, but sometimes the function that is supposed to be called after the animation is done, isn't called. I've poured over all the code and can't figure it out. The code that connects the signal doesn't return an error, even when the function doesn't get called. I can't find any other reason why it wouldn't be called either. I'm sure there is still a possibility that there is a bug in my code, but I was wondering, if the game is processor intensive, is it possible that signals get dropped? Any other things I should look into? I'm on Godot_v3.1.1-stable_x11.64.

	var expl = $Explosion
	var err = expl.get_node("AnimationPlayer").connect("animation_finished", self, "_on_ExplosionAnim_animation_finished")
	print(err)

. . .

func _on_ExplosionAnim_animation_finished(anim_name):
	print('animation done')

Josh

I tracked down the bug a bit more. I think it has to do with me reparenting the explosion Sprite. Let me explain a bit more. I have two RigidBody2Ds. One is a bullet and one is a ship. When a bullet hits a ship, I get the collision point and normal, and reparent the explosion sprite from the bullet to the ship so that the explosion 'sticks' to the ship. It looks and works great, except for this occassional bug.

Here is the relevant code when a bullet hits a ship: body is the ship, this code is in the bullet:

func _on_Bullet_body_entered(body):
	var unique = str(Global.getUnique())
	var node = $Explosion
	node.get_parent().remove_child(node)
	node.set_name("EXR"+unique)
	body.add_child(node)
	node.set_owner(body)
	expl = body.get_node("EXR"+unique)

	expl.show()
	expl.get_node("AnimationPlayer").connect("animation_finished", self, "_on_ExplosionAnim_animation_finished")
	expl.get_node('AnimationPlayer').play("explosion")

Also, I verified the name of the AnimationPlayer is correct and tried the call function animation track. I hadn't noticed the call function animation track, so thanks for that!

Nevermind, I actually found it. I had a func _on_VisibilityNotifier2D_screen_exited(): function that called queue_free(). After the bullet hit the ship, the explosion got attached to the ship, but the RigidBody2D kept moving (invisibly) off the screen, and so queue_free() was getting called before the explosion animation was finished playing...

3 years later