How can I change the anim_player of an AnimationTree node while the game is running?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By quewon

Hi. I’m trying to make a character blink, and so I’ve created an AnimationPlayer that has all the same animations as the original one except that the character has its eyes closed. I thought this would be a simple solution because all I would have to do is switch the AnimationTree’s anim_player property when the character is blinking.

Unfortunately doing $AnimationTree.anim_player = NodePath("BlinkPlayer") doesn’t seem to work… I’ve tried $AnimationTree.set_animation_player() as well, which doesn’t yield any different results.

The resulting warning:

E 0:00:02.239   _process_graph: AnimationTree: no valid AnimationPlayer path set, disabling playback

  <C++ Source>  scene/animation/animation_tree.cpp:762 @ _process_graph()

Is it impossible to change the animation player while the game is running? Should I find a different method to get the player blinking? Thanks!

Did you found an solution to this? I’m needing the same right now…

Mario Mey | 2022-07-16 14:42

Forma 1) si solo tiene que tener 1 personaje.
crear nueva forma heredada del objeto y con ello copiar la animación a la original.

Forma2) si tiene que alterar constantemente animaciones cada vez que carga muchos personajes.

si la animación es "AnimationPlayer2 " y es parte del objeto “OBJETO”

$AnimationTree.anim_player = “…/” + OBJETO.name +“/AnimationPlayer2”

con eso intercambia las animaciones originales con “AnimationPlayer2”
pero previamente tiene que crear el “nodo de animación” de lo contrario no funcionara, lo cual es un problema ya que solo puede crear “nodo de animación” de una “animación” en la “AnimationPlayer” original.

pero se soluciona si duplica los nombres de “nodo de animación”.