Our game features custom combinations for the top and bottom half of the characters. Each top/bottom half is unique and requires different animation files.
The characters have the same animation state machine, its just the motions for each state that needs changing. Ideally we should be able to have a single template Animator Controller with two layers, one for the top half and one for the bottom half. At runtime we should be able to set the motion of each state based on the pieces the player chooses.
However this does not seem possible. Unity 4.1 allowed us to set the AnimatorController at runtime, but we cannot edit the motion of a state via scripting yet.
We were able to set the motion of a clip in code via Editor scripting, using the UnityEditorInternal.State. However this does not help us because we cannot use UnityEditorInternal on IOS. We also tried invoking the method via reflection, but again, did not work on IOS.
Has anyone found a workaround to this limitation on mecanim? Is there any ETA for when this feature will be released? It seems crazy that we cannot yet edit a state at runtime…
It looks like if you have Unity Pro you can do this now:
Animation Layer syncing (Pro only)
Sometimes it is useful to be able to re-use the same state machine in different layers. For example if you want to simulate “wounded” behavior, and have “wounded” animations for walk / run / jump instead of the “healthy” ones. You can click the Sync checkbox on one of your layers, and then select the layer you want to sync with. The state machine structure will then be the same, but the actual animation clips used by the states will be distinct.
I raise this thread from the dead to second that changing the motion of states in code would be great.
I have several characters that share the same state machines, using different animations. I need to duplicate the Animators to use different animations on different characters, and if I have to change/fix something in the state machines, I have to do it in all the duplicated Animators! Pointless. Tedious. Error-prone. Ugly.
It might be it better to just duplicate some states that have unique animations, and have several idle, walk and run states - “WalkHuman” / “WalkOrc” / etc, and control that using parameters. But that is also ugly, and would leave my Animator that much more complicated.
Anything on this? I have been searching the web for the whole day.
This feature was supposed to be included in Unity 4.3, but I have read some info stating that it didn’t reach the deadline. Additionally, previously available UnityInternalEditor methods that may help with this has been made unaccesible (like GetLayerStateMachine). So, right now, I can’t find a way to workaround it.
This is desperately needed. How hard could it be to implement?
I have a bunch of characters that use the same states but with different motions (sprites). It is a 2d game so I am getting animated sprites and using them in the motion category. I am surprised that this hasn’t been implemented and there is no other alternative other than duplicating animators. This is an awful method as if you want to add any more states you have to do it on all animators which takes FOREVER.
I am wondering if there is a workaround that involves placing the data from one motion into the motion used.
This is indeed now possible, and I am using it to share the same Animator Controller across multiple enemies with differing animation clips.
There are some issues though, specifically on how it handles AvatarMasks.
This is how I’m using it (someone else needs to call Init with the proper animator)
public class AnimationClipOverrides : MonoBehaviour
{
[System.Serializable]
private class AnimationClipOverride
{
public string clipNamed;
public AnimationClip overrideWith;
}
[SerializeField] AnimationClipOverride[] clipOverrides;
// Use this for initialization
public void Init (Animator animator)
{
AnimatorOverrideController overrideController = new AnimatorOverrideController();
overrideController.runtimeAnimatorController = animator.runtimeAnimatorController;
foreach(AnimationClipOverride clipOverride in clipOverrides)
{
overrideController[clipOverride.clipNamed] = clipOverride.overrideWith;
}
animator.runtimeAnimatorController = overrideController;
}
}
ok i have Understand after try ! it’s me how it’s work it’s little strange ! but ! why not if this working
so what’s next step please lol !
why that’s i can change overrideController[clipOverride.clipNamed]