Last active
November 23, 2019 20:19
-
-
Save SiarheiPilat/baa75368adcf3dd6652d831cb23847ab to your computer and use it in GitHub Desktop.
Unity animation events or AnimationUtility API does not contain methods for deleting animation clip events at runtime. The following code makes it possible.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Unity animation events or AnimationUtility API does not contain methods for deleting animation clip events at runtime.The following code makes it possible. | |
/// Taken from (with a minor bug fix): https://forum.unity.com/threads/remove-animation-event.78957/ | |
/// </summary> | |
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[i]; | |
if (animationEvent.functionName != functionName) | |
{ | |
updatedAnimationEvents.Add(animationEvent); | |
} | |
} | |
animationClip.events = updatedAnimationEvents.ToArray(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment