Multiple buttons play the animation on first button

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

I have two buttons, each with its own animation player but the same animations.

(The following images are not displayed so I try to describe)
right button plays animation on the left button


The scene has the following structure (excerpt):

Button 1

  • Animationplayer
  • Sprite
    – 2nd sprite

Button 2

  • Animationplayer
  • Sprite
    – 2nd sprite

The animationplayer has a simple animation which replaces “Sprite” with “2nd sprite”

Both buttons reference the same script.

func _on_Card_pressed() -> void:
$AnimationPlayer.play("card_flip")

My intention is:
If I push the first button the animation “card_flip” is played on the first button, if I press the 2nd button the animation is played on the 2nd button.
But if I press the 2nd button the animation is played on the first button.

One solution would probably be to duplicate the animations and rename it eg. “card_flip_2”
But I’m pretty sure there is an easier way.

Any suggestions appreciated
Thanks Boris

:bust_in_silhouette: Reply From: boris0dev

Think I found solution:

  • create for 1 card, which contains the animation player its own scene
  • set for the animation “local to scene” true
  • add this scene to the main scene tree