Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created October 24, 2026 18:53
Show Gist options
  • Select an option

  • Save unitycoder/0df98c9c9e38b45b9f27b94db171c3a0 to your computer and use it in GitHub Desktop.

Select an option

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
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