- Home /
Animation or script transforming?
Hello guys,
I have been looking for an answer to this or for a similar topic on multiple sites and even though I did manage to find quite nice tutorials on how to do one or the other, none of them answered the following question: What is better (performance wise) to have? animation of an object or to just script it to transform position and rotation (so that he actually moves by a fixed amount every frame or second). Especially when it comes to complex movements, like rotation (make it rotate exactly 2 times around z or x axis) and so on?
Animation provides more control on the movement, number of occurrences, speed and so on, but how does that translate performance wise? From my previous experience in programming (not unity), I know that making things be done at runtime by script is a lot better performance-wise. However, I have never worked with animation so this really bugs me.
What is your opinion? Many thanks!
Answer by Andres-Fernandez · May 07, 2014 at 08:28 AM
I can't talk numbers, or the theory, but I can tell you that from my experience, animation clips perform a lot better if the amount of objects to move by code is big.
In one of my last projects there where nearly 50 objetcs that were being translated and rotated by code (using itween if I'm not mistaken) and those translations had to loop indefinitely. What I found was that every time a translation by code ended and new one started there was a huge peak in the performance (tens of milliseconds, maybe a hundred) due to itween elements being destroyed and created again. I created an animation (with an editor script, to make objects translate along same path as the script), set the loop and applied to all the objects. Peaks disappeared.
Maybe it was because of the use of the itween library, but using animation clips made the game run a lot faster than controlling the movement of all the objects by script.
$$anonymous$$any thanks for your answer! This was something I was also kinda felling it's the case, that an animation would use lesser or in the worse case the same amount of resources, but it allows for a better customisation of the movement of the object.
Projects varies. Those are all situational. If like simple rotation, script can adjust rotate speed and call script in Update can modifed by &frameCount which can reduce cost per second.
Your answer
![](https://koobas.hobune.stream/wayback/20220613144432im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Adding animation clips via script 2 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Best Practice For Shader Complexity + IOS 1 Answer
Photon Multiplayer Animations 2 Answers
Scripting animations 2 Answers