How to Change the Motion of an Animation State in an Animator Controller at Run-Time?

TL;DR - My goal is to author a single Animator Controller that can be used by multiple non-humanoid characters. Each character has a unique motion to play for each animation state and needs to assign the motion to the state.

That is, I wish to reuse all the logic of an Animator Controller, but the motions that will be played need to be unique for each character using the controller.

Can this be accomplished in the Unity editor or via script?

The long version:

My game has 30+ non-humanoid characters. All of these characters move through the same animation states (idle, move, jump, etc.) using the same logic (transitions, parameters, etc.) but have unique animations to play in each animation state. Ideally, I want to author a single Animator Controller to express the common animation state machine logic, then reuse this single Animator Controller by dynamically binding the character-specific motions to the animation states in the Animator Controller either somewhere in the Unity editor or at run-time via script.

Can this be done?

It does not appear to be possible via the Unity editor because each animation state explicitly binds to a motion to use in the definition of an Animator Controller. So if multiple characters use this Animator Controller, they will be playing the same animations as each other, which is not what I want. Furthermore, the motion property of an animation state does not appear to be accessible via script.

The only solutions appear to be:

  1. Author the Animator Controller, then create a duplicate controller for each character, setting the character-specific motions in the definition of each character’s Animator Controller. (Needless to say, this is a horrible solution. It’s error-prone and does not scale.)
  2. Write my own code to largely duplicate the functionality of the Animator Controller that will allow me to dynamically bind the motions to instances of the reusable controller logic either at tool-time or run-time.

You can try study this: