AnimatorControllerLayer.SetOverrideMotion isn't permanent.

I’m writing an editor utility that will scan a directory for some images and use that information to automatically build some animation clips and an animator controller and then fill the controller’s states with the clips. For the most part it works ok but I can’t find any way to programmatically set the clips used by synced layer states. I tried calling AnimatorControllerLayer.SetOverrideMotion() but it doesn’t seem to stick. I can write the motion and then read it back but the asset itself seems to never change after I call AssetDatabase.SaveAssets(). I’m guessing that this only stores a temporary value that is never serialized. I am missing something here? Is there another way to accomplish this?

Here is the relevant code

if (layer.syncedLayerIndex == -1)
{
  //This layer doesn't have its own statemachine, use the base layer's fsm instead
  foreach (var childState in controller.layers[layer.syncedLayerIndex].stateMachine.states)
  {
    if (string.Equals(childState.state.name, stateName, System.StringComparison.CurrentCultureIgnoreCase))
    {
      layer.SetOverrideMotion(childState.state, clip);
      return;
    }
  }
}

Sigh. Doesn’t it just figure. A whole day wasted trying figure it out and within an hour of asking I find the answer on my own.

For the record, what I needed was AnimatorController.SetStateEffectiveMotion() using the layer index parameter overload.

1 Like

Thank you. It was very useful.

This bug is still not fixed today, thanks for the workaround.