How expensive are animations compared to say transform.position code and so on?

I have a bit of a technical question for you guys specifically to do with the way the game engine handles animation and code. How expensive ( computer resource wise obviously ) are animations compared to moving the position of an object and so on by code?

I’m thinking about for instance, if I want to animate my gun in a way that simulates running or recoil, I’ve seen quite a few programmers out there in the older version of Unity use nothing but C# to do this. However, with how animating works now it seems to like that would potentially be unnecessary because we can keyframe everything now.

The question is though, would animations slow up the game if you got a lot of them put together and I should use code instead for things like recoil and running animations etc.? Or is the difference actually so small it wouldn’t really matter much, because in the end, I’m still changing just the position and so on depending on what button I press, just using a different interface to do it.

I’m asking because I’m just wondering if all these old tutorials are looking at this stuff because there wasn’t proper animation tools back then? ( They’re 2011 and so on ) or is there a more specific reason for this. If any of you have looked at the official Unity tutorials a lot like I have you’d know that there’s a rocket launcher tutorial for example where this guy specifically uses animation to simulate recoil rather than code.

If you’re modelling the gun in a 3D program, you can remove all of the animated bones in-game through the import tab (. This is a lot more performant than moving the bones.

Moving a transform’s position is not free, especially in large rigs, where you have very many child objects. If you are just moving the root bone, there should be no noticeable difference between different methods.

1 Like

Thanks for that, I was wondering because dealing with these kind of things from an animating perspective was fairly easy so I wanted to know whether it was okay to carry on using it or I should look at other methods for optimisation purposes, your explanation cleared things up nicely.