Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

get time of animation clip in Animation(legacy) component?

Discussion in 'Animation' started by FeastSC2, Nov 1, 2018.

  1. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    456
    I would like to get the playtime of an animation clip, this way I can stop playing the animation then restart it at a later time when I'm unpausing the game.

    I mean the animation clip used by an Animation(legacy) component and not an Animator.

    How can I access that information?
     
  2. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    456
    Does no one know this?
     
  3. LurkingNinjaDev

    LurkingNinjaDev

    Joined:
    Jan 20, 2015
    Posts:
    1,172
    All animation should stop if you pull Time.timeScale to 0 and should continue when you put back the original value.
    Also you can pause if you set the individual animation.enable = false; and should continue when you set it true.

    Does any of these work for you?

    BTW: animation.clip.length;
    https://docs.unity3d.com/ScriptReference/AnimationClip-length.html
     
  4. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    456
    Time.timescale doesn't work and animation.enable sets the animation back to the start. The length was to get how long the whole animation lasts and not where it's at in that animation.

    So I still don't know how to do it.. ;s
     
  5. LurkingNinjaDev

    LurkingNinjaDev

    Joined:
    Jan 20, 2015
    Posts:
    1,172
    FeastSC2 likes this.
  6. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    456

    That works great, thanks! AnimationState has all the interesting information. Time.timeScale set to 0 does not stop the animation but that's a good thing because then animation on UI would be stopped when the game is paused. If it's a bug it's a good one.