Search Unity

Simple Animation without Animator, maybe via script.

Discussion in 'Animation' started by zh4r0naX, Jan 25, 2020.

  1. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71
    Hi,

    while ive read your current free ebook ( which handles the improvement of ingame performance ) I came to a point where it says, developers tend to use animators extensively. Well why wouldnt they no where is another option shown for simple animations. At least i didnt see one.

    So my question, for simple effects, which consist out of 1 animation file, how to get rid of the animator and the whole overhead ? I just want to update the sprite, maybe adjust some other variables like light size etc. and send an event at the end of the animation.

    How can i do this via script and without too much overhead ? The most performant way ? Do i need to use legacy animations then ?

    Thank you for your time.
    Justin
     
  2. CptKen

    CptKen

    Joined:
    May 30, 2017
    Posts:
    216
    You need to use the playable graph API for this kind of thing. Don't bother with legacy, it's called legacy for a reason.
     
    Last edited: Aug 7, 2020
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    The "legacy" Animation component is by far the fastest way to play back animations in Unity. For playing a single clip, it very easily beats the Playables API. I've checked. It's also the easiest way to play back animations, so I'd recommend you to use it @zh4r0naX

    Playables uses an Animator, but without an Animator controller. It's faster than the Animator+AnimatorController for doin anything, and you can build pretty good tools around it. You need to write a lot of boilerplate to play a single clip, but it's easy enough to put that behind a tool.
     
    kodra_dev, hommfan and NikoBay like this.
  4. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71
    Thank you for your suggestions, for more complex things i would stick to the animator. but for simple hitting effects etc i would love to get rid of the animator.

    @Baste do you have any link for me where i can read into this with some sort of tutorial which you would recommend ?
     
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    The Animation component is really simple. Just stick an Animation component on something, assign the clip, and call Play() (or use Play On Awake).
     
  6. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71
    Great. Thank you!
     
  7. StellarStellar

    StellarStellar

    Joined:
    Jun 1, 2017
    Posts:
    5
    How do I edit an Animation clip if I want to use Playables? The animation editor require me to have a controller to edit a clip. Do I have to create an unused controller for me to use the animation editor? Or there is a way for me to edit a clip directly?
     
  8. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    Kinda. A component can implement the IAnimationClipSource interface, and then you can see the clips you return there in the Animation window.
     
  9. StellarStellar

    StellarStellar

    Joined:
    Jun 1, 2017
    Posts:
    5
    Code (CSharp):
    1.     public AnimationClip clip;
    2.     public void GetAnimationClips(List<AnimationClip> results)
    3.     {
    4.         results.Add(clip);
    5.     }
    It worked, thank you!