Pause animation with Vuforia

Hi everybody,

I’m doing a little Vuforia project with Unity and am desperately searching for a way to pause my animation when the tracker is lost and have it continue at the same position as soon as the imagetracker is back on screen. Pretty much the same way it works with audio (component.audio.Pause();). I have read on the Unity forums here that the way to pause an animation is to set the speed of the animation to 0 but how do i add that to my code? right now the OnTrackingFound says:

Animation animationComponents = GetComponentsInChildren();

foreach (Animation component in animationComponents)

{
component.Play();
}

But where to put the speed variable? :confused:
I know somebody can help me around here! :slight_smile:
Thank you in advance!

Hello!

Well I don’t really know but I guess if you know the name of the animation you could try something like this:

animation["theName"].speed = 0;

And then restore the speed on the OnTrackingFound. I hope this works, if you are using the animator then it also has speed so you can change it to 0!

Good luck! I would appreciate an up vote if this helps you! :wink:

Hey thanks for your reply!
The problem is, that I’m not calling any specific animation but rather all animations in the child object. Do you have an idea what I should add to the code?

EDIT:
Ok I got it!! This is the code to use if anybody is interested:

Animation[] animationComponents = GetComponentsInChildren<Animation>();

		foreach (Animation animation in animationComponents)
		{
			foreach (AnimationState animState in animation)
			{
				animState.speed = 1f;
				animation.Play();
			}
		}

This is what you put in the OnTrackingFound and in the OnTrackingLost just change the animState.speed to 0 and leave out the “animation.Play();”

Thanks a lot for your help llnk7! :slight_smile: