Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Adjusting start and end frames of animation clip with script

Discussion in 'Animation' started by themisharis, Aug 13, 2019.

  1. themisharis


    Aug 12, 2019
    I have a .fbx model which is imported into Unity. (version 2019.3)
    There is one animation clip attached to the model.

    I want to cut the animation clip into multiple clips based on some separation data that I have (the start and end frames of each piece). I want to do this automatically and the process which I would follow manually goes like this:
    * Click on the model file. On the inspector, go under the Animation tab and modify the start and end frames of the animation.
    * Click on APPLY
    Expand the fbx file on the project window. Then duplicate the animation clip file. That's one clip.

    I want to automate this procedure. I found that I don't have access to a clip's start and end frame. So I tried to use ModelImporter to access the import settings of the model and mimic the procedure above. Using that, I tried to also use ModelImporterClipAnimation and then change the fields firstFrame and lastFrame. Then, I use Instantiate() to copy the newly modified animation clip and save that copied clip somewhere else.

    My problem is that the clip doesn't seem to be modified. When I use Instantiate(), the whole clip is copied without any change to its start and end frames. I tried using SerializedObject as an attempt to mimic the pressing of the APPLY button in the model settings window, but I had no success.

    Any ideas about how to simplify the process or of what I am doing wrong?