Crossfade issues

Hi,

I’ve made a basic model with a few bones and an animation in Blender. Everything has imported over to Unity fine.

I have an “Idle” animation that’s just a few frames long.

I have a “jump” animation that also is just a few frames long.

I’m playing my idle animation with
this.animation.CrossFade(“idle”, 2);

I’m playing my jump animation with
this.animation.CrossFade(“jump”, 2);

I’ve tried lots of numbers other than 2.

Regardless of what I seem to do, the animation always “snaps” and does not transition. I was expecting the animation to 'blend" into the other one, but it starts playing the jump animation instantly and does not do any blending. What am I doing wrong?

Yeah, I’ve always found Unity’s animation system a bit confusing.
I believe the issue is due to all AnimationState objects having their weight initialized to 1 by default, you may have noticed that subsequent CrossFade calls seem to work as expected. Try adding the following initialization to your Animation component:

using UnityEngine;

public class MyScript : MonoBehaviour
{
    public Animation Animation;

    private void Start()
    {
        foreach(AnimationState state in Animation)
        {
            state.weight = 0.0f;
        }
    }
}

See if that doesn’t resolve the issue.
For now.
Mmm-yep.

Unfortunately, this still didn’t work.

What does the time value actually expect? What does it represent? Is it the time in seconds it takes to transition?

Still, I can’t seem to get anything to blend at all. It still immediately jumps from the idle animation to the jump with no frames in between. It’s not just the first time, it’s every time my character jumps.

I’m sad yo hear that cause I’ve got the same issue. Cause in the beta the “GoToState” function works pretty find but since I used CrossFade some weird things happened.
I will check this solution asap. Thanks !

Yes, it should be the time in seconds it takes for an animation to go from its current weight to either 0.0 or 1.0.

What wrap modes are you importing your animations with - is your idle set to Loop and jump to Once?
Could you post the script that’s actually playing the animations? It’d help to narrow things down.

Aha! My Idle animation was set to “Once”. I changed it to “Loop” and now things seem to be smoother.

It looks like it is OK that my “jump” animation is still set to “Once”.

I guess the issue was that my “idle” animation wasn’t actually “playing” anymore, so it just instantly jumped to whatever other animation I passed it. By setting it to “loop” i ensured that the “idle” animation was still playing when I triggered the other animations.

I figured something like that might be the case, happens to me all the time.
Did you still have to initialize animations weights to 0.0 or did changing the wrap mode solve your problems?