How does the parent node detect the completion of animation of all its children?

Godot Version

4.2.2

Question

I want parent node do something after child node’s animationPlayer node play animation done.
I know a rather clumsy way of doing it.

  1. every child node set signal animation_done
  2. when node animation play done call back a method, signal animation_done emit
  3. The signal of a child node is bound to a method of the parent node
  4. parent set a variable to record how many child animation done
  5. when this variable equals child node num, that say all child node animation done

I wonder if there is a better way to achieve this

func _process(delta):
	var AnimationFinishedCount : int
	while AnimationFinishedCount != ChildNodeSum
		for child in get_children():
			await child.get_node("AnimationPlayer").animation_finished
			AnimationFinishedCount += 1
	print_debug("all child node animation done")

Note that animation_finished is a signal that is already present in AnimationPlayer, you don’t need to create a separate signal

1 Like

hi,thanks for your answer.use signal of animation_finished is elegant than use custom signal
when I try this way.I found some problem.




I don’t know why parent: all child animation play done is print before child_x animation_play_done
Maybe it’s a little problem that doesn’t matter. my resolve: put animation_play_done
forward for a short period of time in animation time track

hello, past me,you should not call animation_play in child ready.you should:


1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.