Weird Error for "Animation not Found..."

Godot Version

4.2.1

Question

Screenshot 2024-08-15 160928

I’m receiving an error that says AnimationPlayer can’t find animation “X”. The name of the animation is irrelevant because I made this function to make sure the correct animation always plays. It takes new_stance and new_animation and finds the correct animation to play unless it’s one of the three animations in the match statement. These don’t have any stance correlated to them and therefore are only named Jump, Land, and Roll. The match “overrides” the previous play() call and plays the correct animation. However, the first play() still runs and throws me an error (Example: “player_animation.gd:133 @ change_animation(): Animation not found: StandJump.”). Is this ok to leave as is, or is there a solution I should use? Thanks so much for your time.

This begs the question:

  • At which point in the code procedure is change_animation() called?
  • Why does it have the StandJump value as new_animation put in?
  • For future sake, please add a fallback match-case to check for potential animations that you don’t expect
match new_animation:
   ...
   _:
      print("Unknown animation passed: ", new_animation)
   ...

After reading through it again, I believe the following line is error-prone:
play(new_stance + new_animation)
As this produces Stand + Jump, which in this case does not exist.

1 Like

After thinking about it for some time, I added another condition to change_animation(). exception is only for any animations that have no stance. Stance can be “Stand”, “Crouch”, “Sword”, etc. Basically stances share similar animations like running, walking, idling but they have different conditions set to them. Also change_animation() is linked to a signal. The signal is emitted when the player script detects that an animation should be switched. Thanks for helping me think about this!

Screenshot 2024-08-15 171744

No problem, I was just unsure where the code verifies if an animation with the name stance+animation existed.
From what I imagine, the combination of 4 stances and 4 animations would lead to 16 different animations that are required to exist.