Catch Animation Event

Acer

Member
I'm trying to catch an animation event that I have created but its not working.

I have added my own script to an item and the debug log works.
C#:
    private void OnEnable()
    {
        Debug.Log("START EVENT!");
        EventHandler.RegisterEvent<ItemAbility, bool>(gameObject, "OnAnimatorItemUse", OnAnimatorItemUse);
    }

    private void OnDisable()
    {
        Debug.Log("END EVENT!");
        EventHandler.UnregisterEvent<ItemAbility, bool>(gameObject, "OnAnimatorItemUse", OnAnimatorItemUse);
    }

    private void OnAnimatorItemUse(ItemAbility itemAbility, bool activated)
    {
        Debug.Log(itemAbility + " activated: " + activated);
    }

The Animator Monitor script handles all the animation events? that comes from function ExecuteEvent and Execute the event in the string field?
 

Attachments

  • opsive_animation_event_question_01.png
    opsive_animation_event_question_01.png
    72.1 KB · Views: 3
OnAnimatorItemUse doesn't have any parameters since it's coming from the animator. If you do a search for OnAnimatorItemUse you can see an example usage:

Code:
EventHandler.RegisterEvent(m_Character, "OnAnimatorItemUse", OnUse);
 
OnAnimatorItemUse doesn't have any parameters since it's coming from the animator. If you do a search for OnAnimatorItemUse you can see an example usage:

Code:
EventHandler.RegisterEvent(m_Character, "OnAnimatorItemUse", OnUse);
Sorry I still don't understand.
I just want to catch a custom made event from the animator.
I maybe should not have used the OnAnimatorItemUse as an example but lets say I have named it OnAnimatorMyCustomEvent.
 
You can use the same code, except replace the string with your own value. Make sure you are registering the event on the character GameObject and not the GameObject with the Animator.
 
You can use the same code, except replace the string with your own value. Make sure you are registering the event on the character GameObject and not the GameObject with the Animator.
Aaa yes that was it, thank you Justin. The script was not on the Character gameobject.

But why does it only work from the Characters gameobject and how do I call it from somewhere else?
 
Last edited:
Animation events are always called on the character. For your own events that you trigger you can call them on any object, similar to the example on this page:

 
Back
Top