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

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.

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][1], 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*;*

if (animationEvent.functionName != functionName)
{
updatedAnimationEvents.Add(animationEvent);
}
}

animationClip.events = updatedAnimationEvents.ToArray();
}
[1]: https://forum.unity.com/threads/remove-animation-event.78957/