Play animation in edit mode

I’m trying to make an animation play in edit mode so I can preview it in an editor window. I found this function:

AnimationUtility.StartAnimationMode

Here’s the link to the doc http://unity3d.com/support/documentation/ScriptReference/AnimationUtility.StartAnimationMode.html

It sounds like it does what I want just can’t figure out how to use it or what it actually does.

I can’t just use the animation window since I’m planing on taking snapshots of the animation to create a 2D animation strip.

Anyone knows?

After taking a closer look at the docs It seems to me that AnimationUtility.StartAnimationMode has more to do with saving the state of the objects so they can be reverted after stopping animation mode.

This might be useful, but I still haven’t gotten the animation to play, do I have to get the curves and sample them myself? Anyone know?

How about using the Animation Window?

I’m making an editor script that converts 3D animation into 2D sprite based animation for iphone games, so that won’t work for that purpose.

Ahhh, in that case maybe something using [ExecuteInEditMode] might help.

The whole thing is already inside an editor window so no need for [ExecuteInEditMode], everything seems to be working fine but the animation just doesn’t play, I figure this is because animation is time based and there is no time running in edit mode, but how does the animation window do it then?

Found it!

Animation.Sample() to the rescue!

Would you mind elaborating a bit on how you got it to work? Animation.Sample() doesn’t seem to cut it for me during edittime… what else is necessary? (setting the animation time, enabling it, what else?)

It works as follows:

anim = GetComponent<Animation>();
anim["MyClip"].time = 2.0F;
anim["MyClip"].enabled = true;
anim.Sample();
anim["MyClip"].enabled = false;
1 Like

Can I be guided on how to do this with an Animator?

The AnimationMode class does what you’re trying to do. Best place to get an example of it is here:

1 Like