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
0
Question by bec_bunsen · Aug 20, 2015 at 08:47 AM · runtimeanimationclipeventsanimationevent

How to create animation event at specific keyframe at runtime

Hi!

I have a script which create an animation at runtime from an array of coordinates. Now i want to add some events at specific keyframes positions of this animation clip.

here is the script for adding the events:

 private var myEvent : AnimationEvent;
 private var e : int=0; // place of the event in events[]
 
 function AddEventToMyAnimation() {
     
    myEvent = new AnimationEvent();
    myEvent.functionName="myEventFunction";
 
    // I set keys for each animation frame
    // so the variable t represents the current frame position on my animation.
    for (var t : int=0; t<animationDataArray.Length; t++) {
 
       if (iWantAnEvent==true) {
         
          myAnimationClip.AddEvent(myEvent);
          myAnimationClip.events[e].time=t;
          e+=1;
       }
       else {
       }
    }
 }
 
 function myEventFunction () {
 
     print("Nice job event added");
 }



I definitely have a problem with the line:

 myAnimationClip.AddEvent(myEvent);

This line seems to crash Unity (close itself) when the script executes at runtime...

Since there's not a lot of documentation about scripting animation events, I guess I'm doing something wrong. Unless it's a real Unity bug issue!?

(docs : http://docs.unity3d.com/ScriptReference/AnimationClip.AddEvent.html)

Comment
Add comment · Show 1
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 Ekta-Mehta-D · Aug 20, 2015 at 12:43 PM 0
Share

Try to add single animation event. Check is it working ?

2 Replies

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

Answer by Ekta-Mehta-D · Aug 20, 2015 at 12:48 PM

Hii..

You want to add multiple events at specific time so you need to create array of animation events although you are calling same function. and specify time to each event.

     private AnimationEvent[] _aEvents;
     private Animator _myAnim;
  
  
     // Use this for initialization
     void Start () {
         _myAnim = GetComponent<Animator> ();
  
         _aniclip = _myAnim.runtimeAnimatorController.animationClips[0];
  
         _aEvents = new AnimationEvent[3];
         for (int i = 0; i < 3; i++){
             _aEvents[i] = new AnimationEvent();
             _aEvents[i].functionName = "myEventFunction ";
             _aEvents[i].time =  i;
         }
   
         _aniclip.events = _aEvents;
         
  
     }

This may help you. Thanks.

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 bec_bunsen · Aug 20, 2015 at 02:13 PM 0
Share

Thank you so much, you're great !!! :) That indeed works with this initialization.

avatar image
0

Answer by $$anonymous$$ · Nov 21, 2018 at 04:38 AM

link text

,link text

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Can one Animation Event be used for a timespan (multiple frames)? 1 Answer

Export objects to a .3DS file at runtime 1 Answer

How to check if a animation is completed 1 Answer

Animation layers, duplicate AnimationEvents. (SOLVED) 3 Answers

Add animation clip at runtime 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