Events

Each animation has 3 events. You can add or remove events from an animation at any time.

Main Method

The main method of adding events is generally faster.

On Start

animation.OnStart(() => { Debug.Log("test"); });

On Update

animation.OnUpdate(() => { Debug.Log("test"); });

On Complete

animation.OnComplete(() => { Debug.Log("test"); });

Alternative Method

Optionally, you can opt for a different method of adding events that may make removing them easier.

On Start

Add Event

Action action = () => { Debug.Log("test"); };
animation.onStart.AddListener(action.Invoke);

Remove Event

animation.onStart.RemoveListener(action.Invoke);

On Update

Add Event

Action action = () => { Debug.Log("test"); };
animation.onUpdate.AddListener(action.Invoke);

Remove Event

animation.onUpdate.RemoveListener(action.Invoke);

On Complete

Add Event

Action action = () => { Debug.Log("test"); };
animation.onComplete.AddListener(action.Invoke);

Remove Event

animation.onComplete.RemoveListener(action.Invoke);

Remove All

You can call UnityEvent.RemoveAllListeners to remove all event listeners.

animation.onStart.RemoveAllListeners();

Last updated