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;
}
}
}