Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Mecanim 4.3 AnimationEvent adding from importer

Discussion in 'Animation' started by Noxwill, Nov 12, 2013.

  1. Noxwill

    Noxwill

    Joined:
    Apr 16, 2013
    Posts:
    18
    I'm having trouble with the new 4.3 feature that lets you add an AnimationEvent directly from the animation importer.

    That's from the release notes today.

    What I'm having trouble with is, there's an Events below Masks in the animation importer, and you can click a button to Add Event, but there's no slider on the timer to tell it at what time to add the event, and I don't see a way to keep track of these events as I add them? They don't show anywhere.

    Also, if you forgo adding the event directly from the importer, you can do it from the Animation window which I also tried, I duplicated an AnimationClip because when I import an animation, they're read-only, so duplicating them allows me to edit them.

    Next I open the Animation window and select that duplicated clip that is within an Animator and it doesn't show as read-only, so I can clearly edit it : except the Add Event button is greyed out!!

    I tried both methods of adding events, what am I doing wrong?
     
  2. joessu

    joessu

    Joined:
    Nov 16, 2010
    Posts:
    88
    Scratch everything i previously said, without docs it's a bit of a puzzle figuring this out.

    You have to select a curve on your animation to add an event to it.
     
    Last edited: Nov 13, 2013
  3. Noxwill

    Noxwill

    Joined:
    Apr 16, 2013
    Posts:
    18
    Ah yeah I have a feeling it's because I don't have Unity Pro that the Animation Window stays greyed out even on editable animation clips.

    I understand now that you can hit play on the preview window in the importer and add events that way, but I don't see a way to manage them, because they don't appear anywhere.

    I think I'm going to stick with G1NurX's Event System for Mecanim, it's been working perfectly for me anyway.
     
  4. joessu

    joessu

    Joined:
    Nov 16, 2010
    Posts:
    88
    Well, once the docs are released this should be explained. I could also add animation curves and edit existing curves in the animation window of my duplicated run cycle! this seems like a mistake unless unity free can now edit mecanim animation curves.

    Even when i did get to add an event to my run cycle, i couldn't add a function because it said "no function selected"
     
  5. joessu

    joessu

    Joined:
    Nov 16, 2010
    Posts:
    88
    gahh... so my function was OnAnimationEvent(AnimationState anim) {}

    Once i removed the parameter it came up in the list. Not sure how i can get an animation state....

    EDIT:

    After adding the event and calling it "OnAnimationEvent" in the animation window and then using this script, i think that is the gist of how to get at stuff.

    Code (csharp):
    1. public class AnimDriver : MonoBehaviour
    2. {
    3.     private Animator anim;
    4.  
    5.     // Use this for initialization
    6.     void Start ()
    7.     {
    8.         anim = GetComponent<Animator>();
    9.     }
    10.    
    11.     // Update is called once per frame
    12.     void Update () {
    13.    
    14.     }
    15.  
    16.  
    17.     void OnAnimationEvent()
    18.     {
    19.        anim.GetCurrentAnimationClipState(0) //....
    20.     }
    21.  
    22. }
     
    Last edited: Nov 13, 2013
  6. Noxwill

    Noxwill

    Joined:
    Apr 16, 2013
    Posts:
    18
    When I add functions from the importer, it does call them.

    In fact, if it finds no receiver (I suspect it does a SendMessage) and you don't have a script on the object that contains the rig that handles that event you added then it gives you an error on the console and says there's no receiver.

    I just don't like the fact that I can't edit these events and I lost all track of them the moment I added one in the importer. I can't find them anywhere.

    I had added 3 blank 'NewEvent's to test and it keeps saying there's no receiver because I don't have a function that handles it, I literally have to delete the FBX and re-import it so I can get rid of these because I don't see any way I can delete the events otherwise.
     
  7. Anonanimal

    Anonanimal

    Joined:
    Jul 3, 2013
    Posts:
    56
    -deleted due to my own lack of intelligence-


    Also, to delete, simply right click the little notch on the timeline.
     
    Last edited: Nov 13, 2013
  8. Noxwill

    Noxwill

    Joined:
    Apr 16, 2013
    Posts:
    18
    Ohhh nice I did not see those little notches AT ALL. Thank you!
     
  9. pha

    pha

    Joined:
    Oct 23, 2012
    Posts:
    20
    The AnimationEvent should work the same way as the Legacy one. In the Importer where you preview your animation. You drag the red bar to the frame you would like to create an AnimationEvent call, you then click the "+" button to add an event. The window will popup, you then create a function call, just put any name for the test. In your script, create a function the same name the one you created earlier. Just print out a debug, and it should work fine.
     
  10. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    470
    Is it possible to add handler functions for the new Mecanim AnimationEvents via extensions? I'm guessing this is complicated by the need for another assembly to call it, but perhaps I got the namespace wrong. Mine is not recognized:

    Code (csharp):
    1. namespace UnityEngine
    2. {
    3.     public static class GameObjectExtensions
    4.     {
    5.         public static void tag(this GameObject gameObject)
    6.         {
    7.  
    8.         }
    9.     }
    10. };
     
  11. HowBoring

    HowBoring

    Joined:
    Aug 27, 2013
    Posts:
    7