Search Unity

Create AnimationClip at runtime

Discussion in 'Animation' started by User340, Jun 17, 2019.

  1. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Is it possible to create AnimationClips at runtime? How about humanoid? Say I have some mo-cap data generated at runtime, how would I go about creating a mecanim-ready animation clip out of it?
     
  2. james_unity988

    james_unity988

    Joined:
    Aug 10, 2018
    Posts:
    71
    Wow, I was just about to post this exact same question! Crazy right?

    I found this repo: https://github.com/newyellow/Unity-Runtime-Animation-Recorder

    However, when I take the same animation clip and try to apply it back to my humanoid character, it doesn't work because it's not a Humanoid clip. There doesn't appear to be any way to mark the clip as Humanoid (the properties are readonly and internal). So at first blush this doesn't seem possible. But hopefully someone can enlighten us here!
     
    User340 likes this.
  3. james_unity988

    james_unity988

    Joined:
    Aug 10, 2018
    Posts:
    71
    Slight update: I was able to use Unity's new FBX exporter to export my rig with the recorded animations and then re-import them. This is a hackish workaround for sure, but it does have the added benefit of using Unity's built-in keyframe reduction, which is definitely required in this case because the animation recorder has extremely dense keyframes.
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Unfortunately it's not possible to create AnimationClips at runtime (except Legacy ones). So you either need to use Legacy animations or apply the mocap data yourself without using the animation system.
     
    User340 likes this.
  5. patrickcraig

    patrickcraig

    Joined:
    Feb 14, 2019
    Posts:
    5
    Hello, I am looking to automate some simple animations using predefined keyframes. I believe this is possible by creating a custom editor window. I was just wondering if you are looking to do something similar and maybe we could solve this problem together, because I had looked at automating the creation of animations at runtime before I knew it could be done through editor window.