Legacy animation some animation playing other not

Hello,

I’m making a character going where the player click. I’m using navmesh to make the move and legacy animation system for the animation (duh)

Two of my animation don’t work.

I have 4 animationClip (idle, moveForward, moveToTheLeft, moveToTheRight)

Each animation is played when necessary through code and state and seems to works (My debug message told me that all is working).

The problem is the moveToTheLeft and moveToTheRight doesn’t work even if they are called without error. Each time they should be playing, the model stop being animated until it change state.

But when I’m putting a model with only the moveToTheLeft (and right) in an animation component it’s working well.

Here is the 2 main functions responsible of the animations.

	/*
	 * setAnimation took the animation clip set in the editor to put them 
	 * in the animation component with a generic name, it allows more flexibility.
	 *
	 */
	void setAnimations()
	{
		// If there is a clip in the editor, add it to the animation component
		if (IdleClip != null)			
			animations.AddClip(IdleClip, "idle");
		if (MoveClip != null)
			animations.AddClip(MoveClip, "move");
		if (MoveRightClip != null)
			animations.AddClip(MoveRightClip, "moveRight");
		if (MoveLeftClip != null)
			animations.AddClip(MoveLeftClip, "moveLeft");
	}
	
	/*
	 * setState is called by thge movement function each time it need to. 
	 *
	 */
	public void setState(EState newState)
	{
		bool changeStateSuccess = true;
	
		// The switch go through all the possible case and play the corresponding animation
		switch (newState)
		{
		case EState.IDLE:
			// We are trying to play the animation set previously
			if (!animations.Play("idle", PlayMode.StopAll))
				Debug.LogError("Animation idle not playing");
			break;
		case EState.MOVING:
			if (!animations.Play("move", PlayMode.StopAll))
				Debug.LogError("Animation move not playing try playing : walk_v05");
			break;
		case EState.MOVING_RIGHT:
			print ("AnimManager move rioght is playing");
			// here, the animation is playing I never received the Error log.
			if (!animations.Play("moveRight", PlayMode.StopAll))
				Debug.LogError("Animation moveRight not playing, try playing : walkRight_v04");
			break;
		case EState.MOVING_LEFT:
			print ("AnimManager move left is playing");
			if (!animations.Play("moveLeft", PlayMode.StopAll))
				Debug.LogError("Animation moveLeft not playing, try playing : walkLeft_v04");
			break;
		default:
			Debug.LogError("There is no animation corresponding.");
			changeStateSuccess = false;
			break;
		}
		// If there is no animation available we don't change the state.
		if (changeStateSuccess)
			currentState = newState;		
	}

And here I am without any solution. Although the legacy system isn’t maintained anymore, does anyone know a solution or can give me an hint?

Thanks a lot people and have a good day.

Where exactly are you calling the animation to play?

You have checks to see if the animation is playing or not… but nowhere do I see animation.Play(“WhateverAnimation”) or animation.CrossFade(), etc…

We created an “AnimationController” which generically could play animations in different ways.

Here’s an example of a method:

protected void PlayAnimation(string animationName)
	{		
		animationName = GetAnimationNameFromList(animationName);
		if(string.IsNullOrEmpty(animationName))
			return;

		//Need to convert the run or idle into correct animation.		
		characterAnimation[animationName].speed = currentAnimationSpeed;
		characterAnimation.CrossFade(animationName);		
	}

Obviously some of code doesn’t relate to you…

I assumed that when you test a function you actually do the function and then verify its return.

So the lines below are executing the Play function and if it fails launch a Debug line. (animations is the Animation component containing all of my animation.)

if (!animations.Play("move", PlayMode.StopAll))
                Debug.LogError("Animation move not playing try playing : walk_v05");

Also the two first animations are working well (“idle” and “move”). I also tested playing without testing the play return ( with just : animations.Play(“move”); ) and also with the CrossFade function but it doesn’t works either.

Is there a special way to configure the animation?

Sorry Eizner, but what do you mean by the sentence below?

I kind of resolved my problem. The problem wasn’t in the animation but, I just messed up in the call of my animation, and ended with the idle animation called nearly everytime.

Stupid mistake.