Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by egoquat · Nov 17, 2016 at 07:20 AM · animator

Jump to a specific frame in an animator

How can I jump and stop on a specific frame in an animator?

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

3 Replies

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

Answer by nullgarden · May 03, 2017 at 07:51 AM

Since a lot of other form answers use an outdated Animation component I figured I'd give a simple answer using the Animator class since I've been struggling with this and finally got it to work.

         private Animator anim;
 
     void Start () {
         anim = GetComponent<Animator>();
         anim.speed = 0f;
         anim.Play("YOUR_ANIMATION_NAME_HERE",0,YOUR_TIME_INDEX_HERE);
         
     }

Where TIME_INDEX_HERE is a number between 0f-1f that represents the time location of your desired frame. (i.e. enter 0f for your first frame and 0.5f for your middle frame). For more info see Animator.Play https://docs.unity3d.com/ScriptReference/Animator.Play.html

So far I could not figure out a way to specify a location based off a particular frame index.

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 ClearRoseOfWar · Nov 17, 2020 at 10:33 PM 0
Share

This needs to be easier to find... Thank you!

avatar image d2clon · Feb 19, 2021 at 06:41 PM 0
Share

Why are you changing the speed to 0?

avatar image nullgarden · Feb 19, 2021 at 11:04 PM 1
Share

@d2clon this is so it freezes on that specific frame and shows as a static image. If you want the animation to continue from that point then you don't need to touch speed.

avatar image
1

Answer by FM-Productions · May 03, 2017 at 07:51 AM

Hi, I think this is what you are looking for: https://docs.unity3d.com/ScriptReference/Animator.PlayInFixedTime.html https://docs.unity3d.com/ScriptReference/Experimental.Director.IAnimatorControllerPlayable.PlayInFixedTime.html

Another possibility is to create different subanimations for one animation in your import settings of your base animation fil. In the "Animations" tab, simply add more animations and set the desired start and end frames. Then use these new animations that start at the desired frame of your base animation.

Comment
Add comment · 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
1

Answer by petzichila · Aug 25, 2020 at 04:02 PM

I had this issue. Apparently, both Play() and PlayInFixedTime() multiply the offset by the animation speed. So if your speed is 1, it will behave as expected, but a speed of 2 will mean will animation starts at double the offset. Accordingly, speed 0 means the offset is completely ignored. I don't know who decided to implement this horrible functionality and then leave it undocumented, but my best guess is an agent of evil, perhaps even Satan himself.

My solution is to set the speed to a value close to 0, such as 10 ^ -10. And if I want an offset of 15 seconds, I set the offset to 15 ^ 10.

This way, these methods will work the same as they would with a speed of 0 if they had been implemented sensibly. For good measure, you should set the speed to exactly 0 in the next frame.

Hope this helps!

Comment
Add comment · 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

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

10 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

Related Questions

2D Animation does not start 1 Answer

Get Animation from Animator 2 Answers

Animator conditions, no bool state selector. 1 Answer

Run sprite animation in editor mode? 0 Answers

Trying to access mecanim floats C#, 1 Answer


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