Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
7
Question by Richard 3 · Nov 01, 2011 at 01:29 PM · animationjumpcontrolstopanimate

Jump to a specific frame in an animation

How can I jump and stop on a specific frame in an animation? I would think this is should be very simple.

Thanks in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

6 Replies

· Add your reply
  • Sort: 
avatar image
11
Best Answer

Answer by save · Nov 01, 2011 at 01:52 PM

You use AnimationState.time to jump to a specific time in an animation.

 animation["MyAnimation"].time = 5.0;

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Richard 3 · Nov 01, 2011 at 02:13 PM 0
Share

Thanks, that works. How would I stop the animation on the chosen frame. Using animation.Stop after the code you provided gives different results with every try. Thanks

avatar image jahroy · Nov 01, 2011 at 03:34 PM 0
Share

I'll guess you do it by executing that code every frame?

avatar image ensomniac · Apr 18, 2013 at 06:41 PM 2
Share

This is a pretty old comment, but I came across a better solution and thought I should post it. You don't have to call this every frame, just keep the speed of the animation at zero:

animation["$$anonymous$$yAnimation"].time = 5.0; animation["$$anonymous$$yAnimation"].speed = 0.0; animation.Play("$$anonymous$$yAnimation");

avatar image as87dgs6asg0a · Dec 17, 2019 at 07:46 PM 0
Share

Hello from 2019. Link is broken in this reply. Here you go: AnimationState.time

avatar image
23

Answer by ensomniac · Apr 18, 2013 at 08:02 PM

Since this is the first post that comes up on Google, here is a slightly more complete answer:

 var desired_play_time = 2.3;
 animation["MyAnimation"].time = desired_play_time;
 animation["MyAnimation"].speed = 0.0;
 animation.Play("MyAnimation");
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nuverian · Sep 19, 2013 at 07:51 PM 0
Share

correct. I like that

avatar image daterre · Oct 30, 2013 at 03:41 PM 1
Share

thank you sir. Saved my day (and my hair)

avatar image IgorAherne · Apr 11, 2018 at 03:26 PM 1
Share

Don't forget you could also use: animation[ myAnimationClip.name ].time = ..... if you don't want to provide hard-coded string

avatar image
11

Answer by ColinKnueppel · Feb 04, 2014 at 02:57 PM

You can change the time of an animation inside an animator by using the: animator.Play("animName",layer int, NormalizedTime float);

A note: "animName" is actually the named anim state in the animator, so whatever you name it, is what it will call. It also can cause the current animation to jump to this named state. I haven't found a way to access animations inside blend trees, but you can use this to jump to frames on the total blend tree.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ArchAngelus · Feb 25, 2014 at 03:49 AM 0
Share

I just tried what Colin said and can confirm it works. I was stuck on trying to jump to frame using an animator but this did the trick. Thanks!

avatar image RayWorld · Mar 12, 2014 at 01:52 PM 0
Share

@colin I think your answer is correct if we are using mecanim and unity4.3

avatar image Jeff_B · Jul 23, 2015 at 03:30 PM 0
Share

Took a while to find this one, but it is simple. Even works in conjunction with Animator.crossfade. Just set speed to zero, and you have a "frozen" animation.

avatar image evilduck41 · Jul 30, 2015 at 10:25 PM 0
Share

I'm confused on where to get the animName from. I am in my animation and using and event call back to have my animation jump to one of three points in the animation at random. So in the Animator how do I get the current animation state name and how do I get the current layer I am on?

avatar image
4

Answer by VillageID_10t · Jan 26, 2015 at 09:27 PM

You really shouldn't need to muck with the speed of the animation

 AnimationState clipState = animation.GetClip( "idle" );
 clipState.normalizedTime = Mathf.Random( 0.0f, 1.0f );
 animation.Play();
 animation.Sample(); //forces the pose to be calculated
 animation.Stop(); // actually commits the pose without waiting for end of frame
 
 

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image redthrawn · Jun 19, 2015 at 08:17 PM 0
Share
  AnimationState clipState = animation.GetClip( "idle" ); //error

Can't convert AnimationClip to AnimationState

avatar image mitaywalle · Apr 16, 2018 at 02:53 PM 0
Share

important remark about anim.Sample() helped me, thanks!

avatar image
0

Answer by Noob_Vulcan · Sep 18, 2015 at 06:45 AM

Well if you want to do that in Animator then use this

Lets say you want to play the animation from the mid frame .This is how u will do it

 getComponent().Play(“Animation_Name”,0,0.5f);

or

 getComponent().Play(“Animation_Name”, 0 , (1/total_frames)*frame_number);

For more you can refer here http://www.unityrealm.com/play-animation-from-frame-unity-5-animator/

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AM-Dev · Nov 29, 2015 at 02:02 PM 0
Share

Hi, how can I reset an animation? $$anonymous$$g. I’ve got a animation playing and the user can trigger to exit the animation at any time. I then want the animation to reset, so it is at frame 0.0f again.

Background: I'm creating an Augmented Reality App. So if the tracking is active objects are visible. After some time (e.g. 5 seconds) the animation starts to play. Then if the user looses tracking the objects are hidden. If the uses finds the tracking again, the objects are visible. Now the problem is that the animated object is still somewhere in the animation where the user left before. But I need it to be at the beginning again.

Thanks

avatar image Noob_Vulcan AM-Dev · Nov 30, 2015 at 05:34 AM 1
Share

Hi , Simply Deactivate your gameobject when they are not visible (right now your renders are deactivating ,not the gameobject ) .

Re activating gameobjects rests the animations .

Or you can use

_animator .Play(“same state you are”, 0, 0f);

  • I'm deactivating my gameobjects in my AR project , and it works fine

avatar image AM-Dev Noob_Vulcan · Nov 30, 2015 at 08:33 AM 0
Share

Thanks for the reply. But it doesn't work for me. Not sure if I understand you correctly. I tried:

 myAnimatedObject.SetActive(false); 

when tracking is lost and the scene is reset. Then I do

 myAnimatedObject.SetActive(true);

when tracking is active again. The object is shown, but the animation is still where it ended when it was interupted.

I also tried

 anim.Play(animName, 0, 0.0f);
 anim.speed = 0.0f;

but that also didn't help. $$anonymous$$aybe I'm doing something wrong with my animator setup? Please check the image of my setup.

Thanks! BTW: What AR sdk do you use? We're working with vuforia. From what company are you? What did you develop already? :-)

alt text

Show more comments
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

Controls Are Acting Wierd? 0 Answers

Transitioning animations based on conditions from a different script. 1 Answer

ANimation doesn't rewind on animation.Stop 3 Answers

Jump animation anticipation 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges