Hey all,
So for game design, specifically, I've heard people say that the number of keyframes in an animation will affect performance but do they really mean the number of keyframes or do they mean the total number of frames in an animation; IE its duration? For example, would a 30 frame animation with a keyframe every frame be less performant than the same animation with only 6 keyframes?
Thanks!
Replies
An educated guess, I believe having one keyframe on every frame --that is, baking the animation onto each frame of the sequence, and setting all tangent types to constant-- is slightly faster than having keyframes spread apart, as there'll be no interpolation involved.
The game engine samples the animation curves of each animated node, so when there's one keyframe on each frame of the sequence, it will directly use the values in the keyframes instead of having to interpolate between two neighboring keyframes and having to calculate ease in/out with the curve tangents.
Okay, so I see that it's not a simple 1 answer for every situation... So generally fewer keyframes would be less memory expensive but the total number of frames in a file, you don't think would affect performance. If for example, I have an animation that is 5000 frames long and only 1 keyframe every 5 frames, you don't think that would affect performance? I mean, I'm not sure how an engine handles animations, if the file size matters as it does for textures for example. I would assume it does make a difference but I'm not really sure.
It was more of a general question rather than engine specific one but checking the documentation is definitely a good idea
If you have a heavy skeletal mesh (say 500 bones), it doesn't matter how long/short or dense/sparse anim you put on it, it will be still heavy.
Alembic files on the other hand, they can indeed use a lot of memory, but depending on the implementation, other than memory footprint, they can be cheaper than regular bone based animation. Vertex texture anim, same thing, its more memory but its way faster to spit out an update than with bones.
There are animation compression strategies, but these usually happens under the hood. Like rounding the animated bones to some lower precision(which does make it lighter), and not much to do with manually removing frames and such.
Either way, your explanation is just what I was hoping for
The memory part of this may have been an issue in the past, like 10-15 years ago, but nowadays, even regular users has a bunch of memory in their computers, so it couldn't be an issue anymore. The mesh itself will probably use more memory than its animations.Mobile devices are a somewhat different story, but they are also getting better.
Let me confirm that guess, the Unreal docs do mention that animation interpolation (how keyframes are interpolated) impacts performance:
(...) we recommend moving toward ~15Hz and under Update Rates at appropriate distances for many characters, as well as disabling interpolation.
You can then do a clean pass, removing any redundant keyframes (keyframes that make no change from the previous one).
Generally the only time you'd optimize your animation by baking all the keys and turning off interpolation is when you know exactly which framerate your game will run at (game runs at 60 fps so bake 60 keyframes per second of animation), or maybe for objects that will only be seen from a great distance. But even then, it's something you'll probably want to avoid as it may cause issues if the game is ever ported to other more powerful hardware in the future where framerate locking is considered unacceptable (PC).