Search Unity

Custom, Animation Time Control ?

Discussion in 'Animation' started by JonPQ, May 30, 2017.

  1. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    120
    Hi,
    I'd like to turn off the automatic Unity animation... and control the time steps myself....
    For example... each frame, I don't want unity to update the mesh, calculate bones and blend shaped and render.... I just want it to remember last state and render....
    Then under my control of script... I want to tell it ok... add X time now.. (or subtract) and re-calculate the mesh output..
    Basically I want control over when animation update happens on each animated object... for some advanced time slicing...
    If I set animation speed to 0, and add time manually this will probably work visually... but is UNity still all doing the same Work behind the scenes anyway (re-calculating everything) ?

    Is this possible ? if so how ? and would it work for both mecanim and legacy animations ?
    Thanks in advance for any help.
     
    Last edited: May 30, 2017
  2. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    472
  3. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    120
    Thanks Chris,
    You can do this, per animation clip.... to artificially change speed of each animation seperately...
    animation["idle"].speed = 0.25; // run idle animation at quarter speed.
    And presumably you can set that to 0 speed.
    Then use this to set the time...
    animation["idle"].time = 0.25; // or it might be "animation["idle"].normalizedTime"
    ...or use the function you linked to above to advance time.

    That should work... But I'm not sure what Unity is doing if you set speed to 0.. is it still doing all skinning calculations... or is there a big performance saving, while its set to 0.
     
    Last edited: May 30, 2017
  4. poprev-3d

    poprev-3d

    Joined:
    Apr 12, 2019
    Posts:
    71
    You can take the animation and set its time yourself

    Code (CSharp):
    1. Animation myAnimation;
    2. ...
    3. myAnimation.clip.SampleAnimation(myAnimation.gameObject, <timeInSeconds>);
    I used this for offline video rendering