Search Unity

Set the normalized time of a Mechanim clip

Discussion in 'Animation' started by petey, Jun 13, 2017.

  1. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Hi there,

    I'm just trying to figure out if there's an option in Mechanim, like in the legacy system, that allows you to set the normalized time of an animation clip?

    I've looked around at a lot of threads but they are old and mixed up with info for the legacy system.

    The closest I have got is to use Animator.Play, but that stops any other transitions from working as it always forces that particular animation to play.

    It was a really useful feature, surely it must be achievable in the new system!?

    Thanks,
    Pete
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    If my limited research is correct, normalized time is applying a 0-1 scale to the overall length of the animation? So the end is 1, the dead middle is 0.5, and the beginning is 0.0. Is that correct?

    Can you explain what you need normalized time for exactly? That might help identify what part of mecanim can provide a solution.

    Edit: A couple links might help
    http://www.daikonforge.com/forums/t...rmalizedtime-issue-when-animation-loops.1776/

    http://answers.unity3d.com/questions/425985/set-the-current-time-frame-of-a-mecanim-animation.html

    https://forum.unity3d.com/threads/get-animation-length-in-mecanim.162505/

    https://docs.unity3d.com/ScriptReference/AnimationState-time.html

    https://docs.unity3d.com/ScriptReference/AnimatorStateInfo-normalizedTime.html
     
    Last edited: Jun 13, 2017
  3. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Yeah that’s the one, the other option in the older system was just to set a clip time with the actual duration of the clip but this just made it an easy 0-1 value.

    One example would be if you had a character driving a car or something you could animate a clip of the character steering through left to right then pump your steering angle input into the normalised time of the clip and have a great steering animation hooked into the movement of the vehicle.
    Currently i think you would have to do a blend between a couple of key still poses to get a similar effect.

    In general though found it useful to be able to modify the time and speed of a clip.
     
    theANMATOR2b likes this.
  4. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    pcg and Rodolfo-Rubens like this.
  5. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
  6. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    yes is the same function call.

    passing 0 as the statehash will only change the time of the currently playing state
     
  7. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Ahh thanks I missed that!
    I think I'm going to go with another solution to this though. I don't want to have to keep track of the current state and it feels like I'm asking for more trouble using an experimental feature.

    Just wondering, is adjusting clip time and speed harder in mechanim because it likes to have full control of that for transitions?
     
  8. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    It different.
    The animation legacy component is more direct, you have a list of clip which you choose from which one to play from script.
    The animator component and the statemachine remove the needs to write code as you code all the logic in a statemachine.

    Still you have full control over clip time and speed with Mecanim, but you need to do it in a different way than legacy
     
    petey likes this.
  9. EmilCoehl

    EmilCoehl

    Joined:
    Jan 29, 2021
    Posts:
    9
    @Mecanim-Dev
    I have a 3 sec animation (activated by trigger, 2 state: idle, walk). when I disable gameobject in the middle of playing animation and enable it back the animation will stuck on that point. how can I reset to start from beggining ?