Search Unity

Generate root motion curves at runtime?

Discussion in 'Animation' started by Arycama, Apr 18, 2017.

  1. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    185
    I currently have some animations that are generated at runtime, which include transform movement either on the root game object, or on a root note parented to the root game object. (The root game object does not move in the latter case)

    In editor there is the Generate Root Motion button, however I can not find a way to achieve a similar result at runtime. The following post suggests that you can apply curves to Animator.MotionT and Animator.MotionQ which will make the engine treat it as root motion, however this does not work for me and shows that the Animator.MotionT/Q properties are missing.

    https://forum.unity3d.com/threads/make-root-motion-in-animation-clip.250723/

    Has anyone got any suggestions to make this work? I'm using the latest version of Unity (5.6). At this stage I am most likely going to use the legacy Animation component, read the 7 position and rotation curves (For every clip) into a monobehaviour, and evaluate them from there, which seems somewhat unnecessary.
     
  2. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    You're going to have to use the Legacy component, because the Animator Component doesn't support Runtime generated clips.
     
  3. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    185
    Thanks for the reply, though I was able to get it to work with the Animator component by using Resources.Load to load an existing Animation Controller with a bunch of empty clips with the same name as the runtime generated clips, and then creating an Animation Override Controller in script, applying it to the animator and applying the overrides to it. Apart from the root motion, it worked fine.
     
  4. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    It works in the editor (because we need to be able to edit clips in the editor), but it won't work if you make a build in a standalone player and try to generate clips there.
     
  5. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    185
    Ah, I see. I didn't realise this as I was only testing in the Editor, but I wasn't using any Editor classes so assumed it would work.

    Are there any plans to allow for runtime generated (non-legacy) animations/root motion in the future? The Unity docs say that all legacy animation features will eventually be migrated into the new animator component, I assume this would include being able to generate animations/set curves at runtime.
     
    Llourn and planetmarijn like this.