Skip to content

Instantly share code, notes, and snippets.

@PopupAsylumUK
Last active January 3, 2024 22:49
Show Gist options
  • Save PopupAsylumUK/d43c527f92a3e061c8e32cb6140a8976 to your computer and use it in GitHub Desktop.
Save PopupAsylumUK/d43c527f92a3e061c8e32cb6140a8976 to your computer and use it in GitHub Desktop.
Automatically renames animations on import from "Take 001" or "mixamo.com" to the name of their import, which I find more useful
using UnityEditor;
using UnityEngine;
public class AutoNameAnimations : AssetPostprocessor {
static readonly string[] renameMatches = new string[] { "Take 001", "mixamo.com" };
void OnPostprocessModel(GameObject gameObject) {
ModelImporter importer = assetImporter as ModelImporter;
//importer.clipAnimations wil be 0 if its using the default clip animations,
//if there has been manual edits or edits by this script the length wont be 0
if (importer.clipAnimations.Length == 0) {
ModelImporterClipAnimation[] clipAnimations = importer.defaultClipAnimations;
bool useSuffix = importer.defaultClipAnimations.Length > 1;
bool reimportRequired = false;
for (int i = 0; i < clipAnimations.Length; i++) {
for (int j = 0; j < renameMatches.Length; j++) {
if (clipAnimations[i].takeName == renameMatches[j] || clipAnimations[i].name == renameMatches[j]) {
string newAnimationName = gameObject.name + (useSuffix ? "_" + j.ToString() : "");
clipAnimations[i].takeName = clipAnimations[i].name = newAnimationName;
reimportRequired = true;
}
}
}
if (reimportRequired) {
importer.clipAnimations = clipAnimations;
importer.SaveAndReimport();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment