Last active
April 28, 2025 20:16
-
-
Save maoyeedy/756d993b533e50265df4b581b238a39f to your computer and use it in GitHub Desktop.
[Unity] Rename Mixamo animation clips to match filename
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 System.Collections.Generic; | |
using System.IO; | |
using UnityEditor; | |
using UnityEngine; | |
public class MixamoAnimationRenamingProcessor : AssetPostprocessor | |
{ | |
private static readonly HashSet<string> NamesToReplace = new() | |
{ | |
"mixamo.com" | |
}; | |
private string NewName => Path.GetFileNameWithoutExtension(context.assetPath); | |
private void OnPostprocessModel(GameObject gameObject) | |
{ | |
if (assetImporter is not ModelImporter modelImporter) return; | |
ModelImporterClipAnimation[] clipAnimations = modelImporter.clipAnimations; | |
if (clipAnimations.Length < 1) | |
{ | |
clipAnimations = modelImporter.defaultClipAnimations; | |
} | |
bool isDirty = false; | |
foreach (ModelImporterClipAnimation clipAnimation in clipAnimations) | |
{ | |
if (NamesToReplace.Contains(clipAnimation.name)) | |
{ | |
clipAnimation.name = NewName; | |
isDirty = true; | |
} | |
} | |
if (isDirty) | |
{ | |
modelImporter.clipAnimations = clipAnimations; | |
} | |
} | |
private void OnPostprocessAnimation(GameObject root, AnimationClip clip) | |
{ | |
if (NamesToReplace.Contains(clip.name)) | |
{ | |
clip.name = NewName; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment