Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 AntLewis · Apr 09, 2012 at 04:19 PM · animationevent

Removing or Editting an animationEvent

Hi, I see there is a way to add an animationevent to a clip at run-time, but can you edit an existing one (i.e. change it's time) or delete it completely from a clip at run-time? The docs don't seem to suggest that you can....?

Thanks

Comment
Add comment · Show 3
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 AntLewis · Apr 10, 2012 at 08:50 AM 0
Share

I've tried just changing the time of a pre-existing animationEvent, but that doesn't seem to work..anyone any ideas?

avatar image GuyTidhar · Apr 10, 2012 at 10:05 AM 0
Share

Have you tired creating the same event with different time and assigning that to your clip?

avatar image JamieFristrom · Nov 14, 2012 at 12:55 AM 0
Share

AntLewis, how did you do that? I'd like to access the animationEvents in my animation just so I have points to play the animation back form, but it seems like they're not exposed at runtime.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Apr 10, 2012 at 02:47 PM

It's not possible at runtime. As you can see there's no function beside AddEvent in AnimationClip to modify / remove AnimationEvents.

AnimationEvents are designed at a part of the animation. I'm not sure why there's no function to remove AnimationEvents at runtime (since there is one to add them), but AFAIK there's no way to remove / change animation events at runtime.

In the editor you can use the AnimationUtility class, but not at runtime.

Comment
Add comment · Show 1 · 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 Simon-O · Sep 08, 2015 at 09:20 PM 0
Share

$$anonymous$$ost likely because Unity only has to inject new events at the right time which is trivial.

avatar image
1

Answer by spilat12 · Nov 20, 2019 at 07:36 PM

Hey @AntLewis I know that I am writing very late - after 7 years, in fact - but maybe it will be useful for someone reading this now, as previous answers might misguide someone. It is true that API provides no dedicated function for removing events at runtime.

But it is/was possible to remove AnimationEvents all along by creating a list of new AnimationEvents and populating it with all the events except for the one that you would like to delete and then copying the elements of that list to the events list of the animation clip. Here is the code taken from Unity Forum, the original has a bug in it, but I fixed it:

     public static void RemoveEventFromAnimator(string functionName, Animator animator)
     {
         AnimatorClipInfo animationClipInfo = animator.GetCurrentAnimatorClipInfo(0)[0];
         AnimationClip animationClip = animationClipInfo.clip;
 
         AnimationEvent[] animationEvents = animationClip.events;
         List<AnimationEvent> updatedAnimationEvents = new List<AnimationEvent>();
 
         for (int i = 0; i < animationEvents.Length; i++)
         {
             AnimationEvent animationEvent = animationEvents[i];
             if (animationEvent.functionName != functionName)
             {
                 updatedAnimationEvents.Add(animationEvent);
             }
         }
 
         animationClip.events = updatedAnimationEvents.ToArray();
     }

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

9 People are following this question.

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

Related Questions

Animation Event - "Function not supported" 2 Answers

How do I prevent events on animations 0 Answers

Mecanim Animation Event is Triggering Every Frame When it is Mirrored 1 Answer

AnimationEvent doesn't recognize overriden methods 0 Answers

Please tell me about difference of AnimationEvent. 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