Accessing animation frames

Hey all,

I am trying to access and display an individual frame of an animation clip if a user presses a key. I don’t see a particular function that will do this, would I have to set each frame up as its own clip upon import?

Thanks,
Matt

Unity uses a time-based animation system rather than a frame based one (like many game engines), so what you’re looking for is the time value. For instance…

animation["anim"].time = 1.0;

…would set the animation to 1 second in. Using your frame numbers instead of time numbers is possible, simply divide the frame number by your frame rate (30 I would assume).

In order to make the animation HOLD on that frame, you should be able to set the speed to zero like so…

animation["anim"].speed = 0.0;

I haven’t actually tested this method of holding on a single frame, but it should work…

Won’t this fail say your frame rate varies alot and the engine skips a frame or two?

Regards,
Marc

If the “frame” in the case he was referring to was one of the frames (keyframes) used to create the animation then no, it won’t fail (“this frame when I created the animation at a fixed FPS corresponds to this point in time, and I’ll use that time within the time-based playback environment”).

Yes, it might fail if you take the run-time frame rate you’re actually getting because that may be 30fps, 60fps or some other value.

Yeah, I meant divide by the frame rate that the animation was authored at (say in maya or equivalent 3d app). For most purposes in-game animation is authored at 30fps. Sorry for any confusion.

mytime = animation[“walk”].normalizedTime;

i use something like that to control an animation through mouse drag. think you could to do what you want this way. check it out in the script ref. it’s pretty well doc’d.