Animation.CrossFade doesnt actually smoothly cross fade

Hi there!

I am making a simple combat system with some animations. There is a combat idle and a normal idle. The problem is that if the combat idle has finished playing a script is chaning to the normal idle, but it doesnt really cross fade, it just instantly plays the idle(same effect as Animation.Play would have)… There´s no problem if I change the animation in between a combat idle.

I hope someone can answer my question

Thanks in advance!

Florian

Can we see your code…? ._.

For showing you the code I simplified it:

this doesnt work, its just instantly going back to the idle animation, with no “smoothing”:

void Update(){
 if(!animation.IsPlaying("CombatIdle"))
  animation.CrossFade("Idle");
}

this works, but only if the combat idle animation is running:

void Update(){
 if(Input.GetButtonDown("Fire1"))
 {
  animation.CrossFade("Idle");
 }
}

I hope this explains my problem…

Have you tried CrossFade with fadeLength parameter? If you increase it, it’ll create a smoother transition.

The problem is with !animation.isPlaying. CrossFade changes between two animations, and if an animation isn’t playing, then it won’t fade. Use CrossFadeQueued instead.

EDIT: Here’s an example of how you could use it

bool wave = true;
void Wave () {
	if(wave) {
		animation["wave"].wrapMode = WrapMode.Once;
		animation.CrossFade("wave", 0.15f);
		wave = false; 
		Idle();
	}
}
void Idle () {
	animation["idle"].wrapMode = WrapMode.Loop;
	animation.CrossFadeQueued("idle", 0.2f);
}

Thanks, I will try it when I am at home.

Ok I solved it now.

The solution isn´t CrossFadeQueued. I set all animations to the wrapmode ClampForever(except the looping ones) and then I can simply have a if

if(characterAnimation[Enum.GetName(typeof(AnimState), _currentAnimationState)].wrapMode != WrapMode.Loop  
			characterAnimation[Enum.GetName(typeof(AnimState), _currentAnimationState)].normalizedTime > 1.0f)
		{
			//animation has ended
		}

that clampforever idea helped me. I dont really get why that works to transition better but it does, I didnt even write additional code it just smoothes it out! Thanks bruh