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