Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Trying to add animation events to a fbx files animation, says read-only, won't save events?

Discussion in 'Animation' started by DoubleLee, Jul 22, 2015.

  1. DoubleLee

    DoubleLee

    Joined:
    Apr 11, 2014
    Posts:
    34
    Hi I bought the Animals Full Pack. It includes fbx mesh and animations for a bear and other animals.

    I'm trying to add some animation events through the Animation window. But it says the animations are read-only. After I add my animations and save the scene, once I reboot unity the events are lost. Why is this and what can I do about it?
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,534
    Duplicate the animation clip into its own asset. In the Project view, expand the FBX file. Select the animation clip child object and press Ctrl-D / Command-D. This will create an asset file that's a duplicate of that animation clip. You can add animation events, edit the clip in the Animation view, etc.
     
    DoubleLee likes this.
  3. DoubleLee

    DoubleLee

    Joined:
    Apr 11, 2014
    Posts:
    34
    Thanks !
     
  4. WILEz1975

    WILEz1975

    Joined:
    Mar 23, 2013
    Posts:
    368
    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 call this simple 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);
    }