- Home /
How to set the duration of a looping animation from the inspector?
Hopefully this is just a newbie question, but I can't seem to see where Unity defines the duration of an animation. It always seems to be a little way after the last keyframe, and rather infuriatingly, even just moving the playhead to a position after the last keyframe extends the animation even further.
I'm trying to make a simple looping spinning cube - nothing difficult. I've set my Wrap Mode to Loop. I've added a curve for Rotation.x, I've set up only two keyframes, f0 = 0° and f60 = 90°. Now this is what I see when I zoom out on my Animation inspector:
Now, can anyone explain
1) where did Unity decide to set the length of my loop to (approx) 58:00 and how do I change that? You'll see there are no other keyframes on any of the timeline objects
2) why, when I move my playhead further right than 58:00 (ish), that extended flat line goes even further - but I can never get it to reduce the length of the animation? Argh!
3) how can I reduce the length of my animation to be 1:00 (i.e., 60 frames) so that my rotating cube looks seamless?
I'm sure I'm overlooking some minor detail. Please enlighten me!
I've just spotted this almost identical question:
http://answers.unity3d.com/questions/240937/why-is-unity-adding-extra-frames-to-animation.html
For the record, I am also on $$anonymous$$ac OS X (10.7.3, 11D50b), but running Unity 3.5.1f2, and I consider this to be a Unity bug.
Answer by Steven-1 · Jul 27, 2012 at 09:22 PM
Had the same problem, found this in the support forums: http://forum.unity3d.com/threads/131340-Reduce-animationclip-length/page2 the script on that page fixes the animation. so thanks to alstonc99, Helmut Duregger and Robin1508, for making these scripts. I used the last version (on page 2, by Robin1508), and it worked like a charm.
Answer by mrldev · May 09, 2012 at 06:14 PM
Set a keyframe for the last frame and set to loop. You have no last keyframe.
Sorry, that doesn't make sense.
1) I do have a last keyframe, the one I defined at 1:00 (frame 60). That's the last frame I want in my animation.
2) If I try to create a keyframe at the actual end of the current animation (let's say around 58:00), so be it. But that's not how long I want it to be! If I then either drag that keyframe leftwards to make it earlier, or delete it, the keyframe moves but the animation still stays at it's long length.
Answer by mrldev · May 09, 2012 at 06:14 PM
I believe you have to set a keyframe at the last frame of your animation and the length is automatically picked up by first and last frames.. Not totally sure but I recall thinking the same thing and then finding the animation was the correct length after puzzling it over.
Thanks for trying but it's not working for me. Please see my comment to your first answer.
sometimes I wonder why people bother registering and typing stuff if they don't follow it up nor care if it helped or not... then I get back to getting a life.
Answer by wowen · May 24, 2012 at 09:39 PM
I'm getting this bug too. I see that the previous answers don't understand that you've already set a keyframe on your last frame. Your animation is naturally starting at 0:00, and ending at 1:00, however Unity is extending the clip to 58:00 for seemingly no reason. You've got two keys, that's obvious, but Unity's acting like there's 3.
This is a very frustrating bug and I would also like a solution.
so you'd like to vote up the question and maybe add a comment to it. not such an invalid answer. bashed
Answer by cregox · Oct 18, 2012 at 02:05 PM
If by any chance you're importing from an FBX and using Unity 4, you can edit the FBX Import Settings / Animations (look at the Inspector when you select the FBX), add a clip and set the length there. This actually works on Unity 3 as well, but I can't see the exact steps in here - I recall it's very similar though. ;-)
Your answer
Follow this Question
Related Questions
Animation Timeline Last Frame Duration 1 Answer
Extract keyframe info from animation clips 2 Answers
Why isn't Cinemachine switching between cameras? 0 Answers
Rotating animation rotating backwards 360 degrees 0 Answers
Is there any good method to keep the collider constant while the local scale shrinking or expanding 1 Answer