Animation Issue in Mobile Build (Animations Swapped)

Hi,

I’m working on a mobile project in Unity and I’ve encountered an issue with the animations. During testing in the editor, everything works as expected: the double jump animation plays when the character performs a double jump, and the idle animation appears when the character is standing still. However, when I build the project for mobile, the animations get swapped: the double jump animation plays when the character is idle, and vice versa.

I’ve attached two screenshots showing the game in the editor and in the mobile build, and as you can see, the animation is different even though they are from the same version of the game.

Has anyone encountered this issue before or have any suggestions on what might be causing this behavior?

Thanks in advance for any help!

The number you see the come from the animator to make sure the animator is not changing states.

 debug.text = animator.GetCurrentAnimatorStateInfo(0).fullPathHash.ToString();

You probably have an order-of-script-execution dependency you don’t realize.

You may need to debug it on the actual device to find it.

Either way, time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Keep this in mind as well:

Anything with Animations / Animators / Mechanim:

Only consider the code AFTER you have done this critical step:

Always start with the Animator state machine and prove it works in isolation, no code at all.

Here’s more reading:

I found the error, in case someone have the same problem mine came from the AnimatorOverrideController, because to change the animations you have too look the animation name, they are not always in the order you add them. This is the wrong code:

 private void SetSkin()
    {
        var overrides = new List<KeyValuePair<AnimationClip, AnimationClip>>();
        overrideController.GetOverrides(overrides);
        overrides[0] = new KeyValuePair<AnimationClip, AnimationClip>(overrides[0].Key, GameData.Instance.GetCurrentSkin().skinJump);
        overrides[1] = new KeyValuePair<AnimationClip, AnimationClip>(overrides[1].Key, GameData.Instance.GetCurrentSkin().skinDoubleJump);
        overrides[2] = new KeyValuePair<AnimationClip, AnimationClip>(overrides[2].Key, GameData.Instance.GetCurrentSkin().skinIdle);
        overrides[3] = new KeyValuePair<AnimationClip, AnimationClip>(overrides[3].Key, GameData.Instance.GetCurrentSkin().skinClinging);
        overrideController.ApplyOverrides(overrides);
    }

And this is the way it worked, looking to the names:

private void SetSkin()
{
    var overrides = new List<KeyValuePair<AnimationClip, AnimationClip>>();
    overrideController.GetOverrides(overrides);
    var currentSkin = GameData.Instance.GetCurrentSkin();

    for (int i = 0; i < overrides.Count; i++)
    {
        var originalClip = overrides[i].Key;

        if (originalClip.name == "Jump")
        {
            overrides[i] = new KeyValuePair<AnimationClip, AnimationClip>(originalClip, currentSkin.skinJump);
        }
        else if (originalClip.name == "DoubleJump")
        {
            overrides[i] = new KeyValuePair<AnimationClip, AnimationClip>(originalClip, currentSkin.skinDoubleJump);
        }
        else if (originalClip.name == "Idle")
        {
            overrides[i] = new KeyValuePair<AnimationClip, AnimationClip>(originalClip, currentSkin.skinIdle);
        }
        else if (originalClip.name == "Clinging")
        {
            overrides[i] = new KeyValuePair<AnimationClip, AnimationClip>(originalClip, currentSkin.skinClinging);
        }
    }

    overrideController.ApplyOverrides(overrides);
}