Different on-screen objects keep swapping sprites while animating (resolved but still posting)

The following was written before I figured out the issue. While writing this post, I figured it out, but I still feel obligated to post this for other people who happen to be similarly hated by the divines

hello!!! my game has multiple types of enemies that should be able to exist on screen at the same time, but for some reason, they keep erratically swapping sprites with each other. it’s really jarring honestly.

example screenshots:


in the first image, everything is fine. in the second image, the bunny on the right has become a tiny deer. in the third image, the deer has become a strange blob of bunny flesh. these screenshots were all taken within less than one second of each other.

Things I DO know:

  • this does not happen when their animators are disabled.
  • this only happens when enemies of different types are on screen at the same time.
  • this does not happen when there are only bunnies or only deers on screen, even if there are multiple.
  • as far as i can tell, there’s no obvious pattern. it doesn’t happen just at the start or end of animations, it doesn’t happen with any consistent rhythm, and it can happen on any animation state.
  • The switching does not happen if only the deer animators are enabled, and the bunny animators are disabled.

i know there are probably several different ways that this could be happening, so i will try to do my best to explain what i am doing.

What I am doing:

  • Each enemy type has a dedicated animator controller (Bunny Anim Controller and Deer Anim Controller)
  • Each animator controller has its own states that link to animation clips unique to the enemy. The bunny has Idle (links to EB_Idle), and Walk (links to EB_Walk) and The deer has Idle (links to ED_Idle), Walk (links to ED_Walk) Charge (links to ED_Charge) and Run (links to ED_Run),
  • I have one enemy script, which is placed on each enemy prefab with several parameters set in the inspector depending on the specific enemy (floats like max health, some enums like IdleBehavior or AttackBehavior)
  • The enemy script switches animations by just straight up calling _ animator.Play(“Run”); or _animator.Play(“Charge”); or whatever, which in theory works because the different animator controllers have states with the same names.
  • The switching happens even if I remove all _animator.Play() calls.

Guess what fixed it. Completely deleting the bunny animator controller and building a new completely identical one from scratch! I feel like it probably has something to do with the fact that the bunny prefab was a modification of the deer prefab that i made by just duplicating and editing it, but . . . that is a problem for the past. Thank you for helping me, spirit of the unity forums. I love you

Would you be able to provide the repro project by filing a bug report when the animator controller is in the erroneous state? That would help us pinpoint the issue and fix it.