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
3
Question by andygeers · Jul 15, 2011 at 05:03 PM · animationanimationevent

Enumerate AnimationEvents

Does anybody know a way to get access to the AnimationEvents for a particular animation from a non-Editor script? I know aboutt AnimationUtility but that's only good for Editor scripts, it seems.

My use case is that I want to be able to add 'tags' to different points on the animation timeline, so that I can start an animation part way through. I figured the events might be a good way to simulate this, since I can use a string function argument as a tag name.

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
1

Answer by andygeers · Jul 17, 2011 at 07:28 AM

One solution I'm trying is to do it at edit time with an editor script that accesses AnimationUtility.GetAnimationEvents, and then just save the tags it finds as data on the game object being animated.

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 Waz · Jul 17, 2011 at 11:43 AM 0
Share

That's perfectly reasonable too.

avatar image Bovine · Mar 10, 2013 at 09:48 PM 0
Share

This is a workable solution - I wanted to know the times so I could detect whether the event has fired already and manually fire it. This is for when I am not playing the whole animation and starting it part way through. The situation was a door animation that fired an event to say the edge the door is blocking (tiled based game) is closed or open. It was possible to 'miss' the even because the door could be opened and closed rapidly.

avatar image
0

Answer by Waz · Jul 15, 2011 at 09:31 PM

You could at Start play the animation through (using Sample, not actually by time passing), and in the animation event function, record the parameter and time of the animation.

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 andygeers · Jul 16, 2011 at 06:15 PM 1
Share

This sounds like an egregious hack, but I like your style! But sadly, Sample doesn't seem to trigger the events (unless I've misunderstood what you meant?). I tried an even worse hack, where I just set the speed the a REALLY big number and tried to Play the animation quickly, but it was so quick that there was no way to get accurate time information at the point where the event was fired.

avatar image Waz · Jul 16, 2011 at 10:09 PM 0
Share

Ooh yeah, it would certainly be a kludge (though not as crazy as using AnimationEvents as tags in the first place ;-), but yes, you're right, Sample doesn't work.

avatar image
0

Answer by Waz · Jul 16, 2011 at 10:12 PM

Okay, far less kludgy idea: have an enum property and increase it by 1 (constant curve) at each tag point. Process the curve to extract the times and associate that back to the enum.

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 andygeers · Jul 17, 2011 at 07:27 AM 0
Share

So I'd have to play through the animation at normal speed first? Given that you think my original idea is a kludge, can you think of a better approach that doesn't require AnimationEvents in the first place? I just quite like the fact that you can place them directly onto the timeline and see them side-by-side with the curves.

avatar image Waz · Jul 17, 2011 at 11:39 AM 0
Share

No, I mean process (in code) the animation curve. Exa$$anonymous$$e the `key's (array of $$anonymous$$eyframes) for the tag enum and I suspect it will be pretty easy to find the tag time points. The question then is only whether the UI for setting the enum increment points is sufficiently comfortable for you.

avatar image Waz · Jul 17, 2011 at 11:42 AM 0
Share

And I mean no offense: a kludge is perfectly warranted when you need to do something but the functionality is not directly available. But it would certainly be that all these suggestions are a kludge simply because we're talking about using the animation system in a way far from intended.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Abrupt change of position between animation transition 2 Answers

AnimationEvent has no receiver, but there is no AnimationEvent 1 Answer

Rotating arm with Animation Event 1 Answer

How to add new curves or animation events to an imported animation? 6 Answers

Can the animation editor create local rotational data? 3 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