LoginSignup
1
0

More than 3 years have passed since last update.

fbxのAnimationEventをスクリプトから削除する

Posted at

ほとんど情報が無かったのでメモです。

市販のアセットなどをインポートしてとりあえず使ってみると、実行中に突然「アニメーションイベントのコールバックが記述されていません」といったエラーが出て焦るアレです。
下記スクリプトはプロジェクト内で選択したfbxからアニメーションイベントを削除します。
使う場合はあらかじめバックアップを取るなどして検証してください。

public class AnimationEventKiller : Editor
{
    [MenuItem("Assets/Kill AnimationEvent")]
    static void Kill()
    {
        foreach (var item in Selection.objects)
        {
            string path = AssetDatabase.GetAssetPath(item);
            var importer = AssetImporter.GetAtPath(path) as ModelImporter;

            SerializedObject so = new SerializedObject(importer);
            SerializedProperty clips = so.FindProperty("m_ClipAnimations");

            for (int i = 0; i < importer.clipAnimations.Length; i++)
            {
                SerializedProperty serializedProperty = clips.GetArrayElementAtIndex(i).FindPropertyRelative("events");
                serializedProperty.ClearArray();
            }

            so.ApplyModifiedProperties();

            importer.SaveAndReimport();
        }
    }
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0