How to add keyframes on imported, read-only, animation?

I have multiple animation imported from 3ds max 8.

they are several animation of the same object divided in multiple .max files (ex fire, walk etc) so I’ve ended up importing them with the @ workaround. Now I need to add an event on them (for ex in the fire animation I have to wake up a fire emitter right in the moment that the weapons fires) unfortunately all the animations are read-only, so no editing is possible.

I know that this question had been posted several times on this forum, but none of the previous answers seems to work for me.

  • I’ve try to copy the entire animation (ctrl+d), and the copy remains read-only
  • I’ve try the script for copy the animation keyframes to a new anim file (I’m unable to find that script now, but if someone need it I can search better…) but the problem was that this script copy only the animation, I have a whole object with multiple mesh and materials that was lost…

So please someone help me… If you need I can provide the .max file or the demo or the entire project as well…I need to fix this thing very badly.

Thanks

You have to duplicate the animationclip-asset. Select the animation clip in your imported model and press ctrl+d. Now you should have a seperate AnimationClip file. This animation clip have to be added to an instance of your model. Just drag your model asset into the scene and replace the referenced AnimationClip in the animation array. After you added the AnimationClip to your model you can open the animation editor window and select your model in the hierarchy. Select the right animation on top (if there are multiple) and you can edit anything in this animation. All changes will be saved to the .anim file since that's the animation you're using now.

You can't replace the AnimationClip on the imported model itself but you can create a new prefab out of the instanciated model in your scene. This prefab will used the assigned AnimationClip.

I have created a special AssetPostProcessor which automatically extracts the .anim files and add them automatically to the model prefab since we have 90+ animations ;)

edit

I've created a small test scene with your model:

AnimationEventsTest.unitypackage

All I've done is:

  1. Draged the model into the scene
  2. Created a new prefab ("Unit_Prefab")
  3. Draged the model onto the prefab to store the model in the prefab
  4. Assigned the seperate AnimationClips("moverun1.anim", "idlefiring1.anim") to the animation array on the new prefab.
  5. Added my test script to provide a function for the AnimationEvent.
  6. Select the model in the scene and open the animation window.
  7. Added two AnimationEvents for the run animation.

Your idle_firing animation seems to be empty, but the run animation works. Oh and i cleaned up unnecessary/duplicated textures. All the animation-fbx files doesn't need to have a material / texture. Unity just need the AnimationClip. Actually after you duplicated the AnimationClip you could completely remove the animation-fbx files. Only when you want to update your animation you have to reimport the animation and duplicate the Clip again.

Because of that procedure we created a specialized AssetPostProcessor which does this steps automatically. If you need to do this 90+ times it's no fun ;)

I remember figuring out a way to unlock the read-only status on anim files on a previous project but it escapes me now. The best alternative I can think of if you just want to add events to your animations you can do it in the animation import options.

Just double click your animation file and expand the Events menu. Sadly the precision isn’t perfect, its kind of hard to pick an exact key frame. Once you add an event you can name a function it calls and specify and input argument (float, int or string). You will need to link it to an object with a public function with the same name you specified earlier. I will try and update this if I find a better solution.

The clip duplication technique is very cumbersome.
With dozens of clips and the need to edit them from the program (Maya, Max, Blender etc …) becomes some problems…

The best solution is to insert the events in the animations at runtime, in the start function with this function:

void AddEvent(int Clip,float time, string functionName,float floatParameter)
{
    anim = GetComponent<Animator>();
    AnimationEvent animationEvent = new AnimationEvent();
    animationEvent.functionName = functionName;
     animationEvent.floatParameter = floatParameter;
    animationEvent.time = time;
    AnimationClip clip = anim.runtimeAnimatorController.animationClips[Clip];
    clip.AddEvent(animationEvent);
}

For example:

Animator anim;

void Start () {
    anim = GetComponent<Animator>();
    AddEvent(1, 0.2f, "EmitProjectile", 0);
}

void AddEvent(int Clip, float time, string functionName, float floatParameter)
{
    anim = GetComponent<Animator>();
    AnimationEvent animationEvent = new AnimationEvent();
    animationEvent.functionName = functionName;
     animationEvent.floatParameter = floatParameter;
    animationEvent.time = time;
    AnimationClip clip = anim.runtimeAnimatorController.animationClips[Clip];
    clip.AddEvent(animationEvent);
}

Just stumbled over this - there is another way of dealing with this issue: In the import settings, under the ‘Animation’ tab, scroll down to the ‘Events’ tab to edit events - see attached image, I’m using it to emit footstep events. You can even use the little preview window on the bottom to find the correct spot in the animation. Same for the ‘Curves’ etc. Once you’re done, apply your changes and you’re done.

from unity manual:

When viewing imported Animation keyframes, the Animation window provides a read-only view of the Animation data. To edit this data, create a new empty Animation Clip in Unity (see Creating a new Animation Clip), then select, copy and paste the Animation data from the imported Animation Clip into your new, writable Animation Clip.