Add events to animation with editor script

I am trying to add events to animations with a editor script.
Serializing the object like this works if the FBX file is ascii encoded.

SerializedObject so = new SerializedObject(modelImporter);
SerializedProperty clips = so.FindProperty(“m_ClipAnimations”);

But since we only want to have binary FBX files this dosn’t work.

I tried creating a list of animation events and setting them as the events to the default animation on the ModelImporter.

modelImporter.defaultClipAnimations[0].events = animationEvents.ToArray();

But there are no events added to this.

How can I add events to a binary FBX?

modelImporter.defaultClipAnimations is a read only property.

try this

ModelImporterClipAnimation[] clips = modelImporter.defaultClipAnimations;
clips[0].events = animationEvents.ToArray();
modelImporter.clipAnimations = clips;

It doesn’t matter if the fbx file is ascii or binary, the model importer doesn’t care

Thanks, it worked perfectly.
Just another question, I want to have events like this
AnimationEvent firstFrameEvent = new AnimationEvent()
{
time = 0f,
functionName = “FirstFrame”,
};
animationEvents.Add(firstFrameEvent);

AnimationEvent lastFrameEvent = new AnimationEvent()
{
time = 1f,
functionName = “LastFrame”,
};
animationEvents.Add(lastFrameEvent);

But for some reason those events don’t get triggered everytime, so my solution is right now that I have the first event on 0.001f and last on 0.99f but that is to much of a delay on large animations.

How can I improve this behaviour?