Created
October 24, 2026 18:53
-
-
Save unitycoder/0df98c9c9e38b45b9f27b94db171c3a0 to your computer and use it in GitHub Desktop.
AssetPostprocessor script that rounds the animation events of clips imported from fbx to the nearest frame
This file contains hidden or 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
| using UnityEngine; | |
| using UnityEditor; | |
| public class RoundFBXAnimationEventsToFrame : AssetPostprocessor | |
| { | |
| // Unity recommends incrementing this version number when the postprocessor's code/behavior is changed | |
| static readonly uint k_Version = 0; | |
| public override uint GetVersion() => k_Version; | |
| void OnPostprocessAnimation(GameObject root, AnimationClip clip) | |
| { | |
| if (!assetPath.EndsWith(".fbx")) return; | |
| float frameTime = 1f / clip.frameRate; | |
| var events = AnimationUtility.GetAnimationEvents(clip); | |
| foreach (var evt in events) | |
| { | |
| evt.time = Mathf.Round(evt.time / frameTime) * frameTime; | |
| } | |
| AnimationUtility.SetAnimationEvents(clip, events); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment