First post here, yay! Just got my hands back on Unity, trying and testing stuff. Kinda 3-weeks-still-a-noob here.
I was wondering which system to use for relatively basic movements on objects.
My example is a physical button in world (not UI) that you push to trigger something somewhere else. I tried using build-in animation system, works great, but I had to create 2 animation files (push & release) and put an animator component on the gameobject. I then trigger the animation state play when I push the button.
I just tried DOTween and I’ve got the same result (close enough) using 3 lines of code in my button controller.
What’s the best method? Performance-wise, like if in the case I have a lot of buttons?
Do you think of any better solution? I heard of Playables but didn’t fiddle with it yet.
DOTween should be much more performant, especially if by “built-in animation system” you mean the animator / playables, which has too much overhead for simple animations.
Personally, I would not recommend to use DOTween for your animation except if you really, really, really need performance. As a beginner, you should not even think about that till the moment your game start to lag. That being said, DOTween can be use for a variety of thing, not just animation. By exemple, you could use it for movement of a projectile or a camera. You could even use it to feed the animation controller.
Some reason why I would recommend you to use the animator controller:
It is easier to work with the animator controller. You do not need to be a developer to be able to create animation. Every Unity user knows the animator controller.
You will need to use the animation controller if you want more complex animation. Adding a second library for the animation will make it harder to maintain your project.
The animator controller is more flexible. If you change your idea and you need more complex animation you wont need to convert anything.
Having dozens more animators than you really need is a quick way to lose performance without you knowing why. In fact Unity used to suggest as a “pro tip” to not use the animator if you cared about performance.
(there have been some optimizations to the animator recently, after years of it being abandoned, probably because the DOTS animation won’t be ready for a while so it will stick around for quite a while longer, but stuff like this: We removed all our Animators and gained 30 FPS - [Alternatives to Mechanim] are probably still very relevant).
I would agree with the above advice if we were talking about legacy Animation, but that is in semi supported status and can open a separate can of worms.
Animator controllers may be more flexible, but they are also very prone to things getting out of hand, fast, and then you need to spend time organising them and debugging them.
Tweening is more predictable and a good habit to get into for simple animations.
And, finally, sure, you can use animators and wait until you get a performance issue, but then solving that performance issue is not really easy, or very possible. It’s not like you can easily rip out all animators and replace them with tweens with the press of a button. You will probably need to refactor a ton of stuff and complete trash your animator work and start from scratch.
Learning how to use tweens effectively is a very useful tool, you should get in the habit of using. Then you can decide if you want to use the animator for some stuff for the extra comfort.
Yes I was talking about the animator, sorry!
I always tend to try and get the better system, and I know I’m thinking about performances at an early prototyping stage when I shouldn’t, it’s costing me a lot of time ahah.
I planned to use DOTween for the UI anyways, so I figured I might use it for simple anims that don’t require states.
I get your point. But I love code! It’s fun to tinker with the animator, more fun to do it with code
I know I’ll have much more complex animations and I certainly will use the animator controller for those!
I was thinking about that as well, but the word “Legacy” doesn’t strike me as good for the longer term!
I also agree that it’s better to use a tweening library for simple animations instead of Animator.
DOTween is quite good for that, but it allocates a small amount of garbage-collected memory every time you start an animation. This may not be a problem if you’re not playing a lot of animations, but can pile up when the project grows bigger.
So for the unmatched performance, I can recommend the PrimeTween library that I developed. It never allocates garbage and beats DOTween in runtime performance up to 2x times.