Search Unity

Go to end of animation automatically

Discussion in 'Animation' started by Primoz56, Jun 7, 2019.

  1. Primoz56

    Primoz56

    Joined:
    May 9, 2018
    Posts:
    369
    Hi all,

    So i have added an animation to an object which would either enable or disable the object through a smooth animation. Everything works fine, but I can't figure out how to make the animation 'not play' but still get the end state of the previous animation if possible.

    So my object can begin either ENABLED or DISABLED (just naming), and switching between the two plays an animation, which leaves the object in a certain state that i'd like it to be (objects visible, colours etc). I can make it work fine if i make the default state disabled, but if its ENABLED by default, then when i first see the object it will play the animation as if I just enabled it. I do not want this. I would want it to not play any animation when i open the container window regardless of which state it is, and only play the animations when I click on it (to toggle).

    I would like to do this via Animator please, i mean code can fix anything but it seems very dirty/messy and not reusable.

    Thanks,
    Primoz
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    You might be able to make an "Enable Immediately" which plays the enable animation at super high speed, but that might still have it disabled for the first frame.

    I don't think there's any other way you could do it with just the Animator Controller. You're going to need a script to actually control it at runtime, so you might as well just add some startup code to that script.
     
  3. Primoz56

    Primoz56

    Joined:
    May 9, 2018
    Posts:
    369
    ok thanks, was hoping there might be a cleaner way to do this, as it sounds like a very common scenario
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    It's entirely possible that there's a way I don't know of because I don't like the Animator Controller system so I don't use it at all.
     
  5. Primoz56

    Primoz56

    Joined:
    May 9, 2018
    Posts:
    369
    what do you use? i noticed a considerable performance hit and 'lag' when doing animation programatically
     
  6. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I made a plugin called Animancer (link in my signature). It lets your scripts simply reference the AnimationClips they want and pass them directly into the Play method so you get full scripting control without setting up an Animator Controller separately. The performance is pretty similar, usually slightly better.
     
  7. Primoz56

    Primoz56

    Joined:
    May 9, 2018
    Posts:
    369
    ok thanks, great idea btw