• 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
1
Question by NoobWhisperer · Apr 10, 2013 at 04:34 PM · mecanim

How can I sample a Mecanim Animation at a specified time?

Hi All -

Does anyone know a way to force a Mecanim animation to a particular time and sample the animation? I have tried using ForceNormalizedTime method on the Animator which does seem to set the time there and the animation will "pick up" from that point the NEXT TIME IT IS UPDATED, but it does not immediately place the animation to that point in time.

In my case I want to loop through (in C# code) various time values of a Mecanim animation and collect some information about the vertex positions at those times.

(I have not used legacy animation system, but documentation looks like it was possible with Animation.Sample in the legacy system).

Thanks in advance!

Comment
Add comment · Show 2
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 Antony-Blackett · Apr 08, 2014 at 12:04 AM 0
Share

Did you find a solution to this? I need a substitute for Animation.Sample() as well.

avatar image stomir · Oct 16, 2014 at 04:32 PM 0
Share

BU$$anonymous$$P


I spent like an hour looking, and THIS is what I find? Unanswered question?

2 Replies

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

Answer by juwambo · Oct 08, 2015 at 03:35 PM

I just had exactly this problem and Google only brought me here, but I managed to find a solution myself :)

So if anyone else is looking for answer to this in the future, here's how you can get an Animation to instantly change to a specified frame:

First you have to set the animation and time via animator.Play(...) and then you can force the animator to update via animator.Update(float deltaTime).

Example:

 int iLayer = 0;
 float fNormalizedTime = .5f;

 //Get Current State
 AnimatorStateInfo aniStateInfo = animator.GetCurrentAnimatorStateInfo(iLayer );
 
 //Set Normalized Time
 animator.Play(aniStateInfo.shortNameHash, iLayer,  fNormalizedTime);

 //Force Update
 animator.Update(0f);





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 ensomniac · Feb 29, 2016 at 11:00 PM 0
Share
  • for animator.Update()

avatar image Bunny83 · Mar 01, 2016 at 12:31 AM 0
Share

Since the question (which just got bumped) is very old and the original poster wasn't on for over a year i accepted this answer.

avatar image
0

Answer by komodor · Jan 29, 2019 at 02:30 PM

https://docs.unity3d.com/ScriptReference/AnimationClip.SampleAnimation.html

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Unity 4 Mechanim: play audio when a foot touches the ground 4 Answers

mecanim blend direction 0 Answers

Mecanim animation not played 1 Answer

Javascript to control parameters of animator controller 3 Answers

Mecanim: NullReferenceException 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