Accessing a Mecanim state through scripting, then changing the associated clip--Can it be done?

I have a character using Mecanim with all its main animations run by a controller script, but sometimes I want it to run unique animations while interacting with specific objects and don’t really want those stored in the animation controller. It would allow me to keep the state machine manageable while also allowing me to add objects more easily in the future.

I’m nearly certain that this can’t be done with Mecanim in its current form, but I’m hoping I’m wrong. Below is an example of what I’d like to do. This would run in a method in the object after the player Gameobject is passed in as user:

Animator userAnim = user.GetComponent<Animator>();	
userAnim.GetState("Interaction").SetClip(this.action); //I know this doesn't exist
userAnim.Play("Interaction", 0);

If the legacy system is the only way to do this, is it possible to run legacy animations on a character that is also using Mecanim or do I need to convert everything to legacy to pull this off?

There IS a way it’s just a bit more tedious than you’d expect. Unity - Scripting API: AnimatorOverrideController

@castor you can try something like the following - not literally, this is stripped from a class with other goals. It’s a tad obnoxious (childState is not the same as a state?!?) but it’s what the API allows us to do currently.


    // Gets all states from currently selected layer
    var layers = AnimatorController.layers;
    var clipNames = new Dictionary<string, string>();

    var childStates = layers[Layer].stateMachine.states;
    foreach (var childState in childStates)

    _animatorStates = Animator.GetStates();
    foreach (var animatorState in _animatorStates)
        StatesData.Add(new FsmState(, animatorState.nameHash, clipNames[]));