Simple Animation without Animator, maybe via script.

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

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.

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.

3 Likes

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 ?

The Animation component is really simple. Just stick an Animation component on something, assign the clip, and call Play() (or use Play On Awake).

Great. Thank you!

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?

Kinda. A component can implement the IAnimationClipSource interface, and then you can see the clips you return there in the Animation window.

3 Likes
    public AnimationClip clip;
    public void GetAnimationClips(List<AnimationClip> results)
    {
        results.Add(clip);
    }

It worked, thank you!