Welcome to Armanimation, today we will digest the hardest topic on this channel. Optimization of your Spine projects. I'm Arman, being a spine animator and having 4 years of coding experience in the past I can tell you that you should not spend any second optimizing your projects that you have already done, unless developers found performance issues and narrowed it down to your Spine project.
Dear developers, better if you don't limit animators without measuring the game. Honestly, you should not worry about the performance at the beginning and even if you do, believe me the bottleneck is most likely not Spine. However, The purpose of this video is to teach animators to build skeletons in an efficient way, so it is less likely that Spine is the bottleneck in the game.
Video will also help you to construct flexible rigs with less effort. To better understand how skeletons perform at runtime check official documentation, I will drop the link in the description, along with some other useful links. If you are animating projects to be rendered as a video or a sequence, none of this matters, ignore this Video, but don't just leave, subscribe, maybe the next video is just for you.
Let's start from Photoshop or wherever you have your art. Mainly animators receive the art in original size which would mostly be unnecessary big. The size of the images in the spine can be resized during the export so it cannot be a performance issue.
However my advice is to consider the highest resolution device that your game will run on and resize your art to match it before even importing into spine. This way you will avoid massive skeletons with bone scale cranked up. Spine can even export multiple atlases using different scale ratios, so later developers can load an atlas based on the user's screen size.
Great let's assume we have resized the art for our needs, what else we can do at this stage, if some of the art pieces have too much empty space make sure to rotate them or even cut into pieces, for better packing. Next if you have some shadows, clouds, smoke anything that is blurry and in the background you can add a [Scale] tag to it. That will make sure that the exported image will be smaller, no worries Spine will stretch it back to initial size, quality reduction should not be noticeable for our already blurry images.
This will help you to pack tighter and smaller atlasses. Once we have prepared our project in Photoshop we are ready to import it into Spine. While rigging we should keep sight of how our assets will be used.
If it's going to be low resolution, on a phone, probably we don't need to rig each finger and strand of hair individually. Don't use more bones and vertices than necessary. It can be surprising how much we can do with just weights.
However, very often we will need mesh attachments. It is very important to resist the temptation of zooming in and adding too many details at this stage. The mesh should be functional and not looking nice.
Add more details where the mesh is going to bend or stretch. If the mesh has hard parts, like this metal gear on her chest maybe you need to preserve it with an extra ring and bind it with an equal weight value for all the vertices. At this stage you should already know how the mesh should behave, maybe it is going to rotate in 3D.
or it is bending uniformly, maybe you want to show elbows while bending, so better to plan before meshing it. After you finish setting up the mesh you will need to bind it to the bones so you can animate it. But what if we want to deform the mesh directly in the animations.
Why not? it is easy, you don't need to rig it with bones and weights. You have more control over the vertices.
And with a soft selection tool you can easily warp any mesh however you want. Or check this out, we can set a custom pivot for any amount of vertices and rotate or scale them. Cool right?
So with all these controls why not deform the mesh all the time? Well it has 2 huge downsides. First problem is that a mesh can be keyed only on one timeline, So you can't animate separate portions of the mesh independently the mesh will deform from key to key as a collection of points each moving by a straight line.
So don't rotate the mesh using deform keys and expect a normal behavior, you will see it shrinking at the middle of the way then resizing back. But the main problem is that deform keys use a lot of memory to store values for every bone weighted to each vertex. And it also increases the data file size, since one of the largest parts of the skeleton data is the mesh vertex.
Let me demonstrate that. I will open the Raptor project, export a JSON as it is now so we compare later, then select all the meshes and key 5 times, and now let's copy them to all other animations. And finally export it, just rename the skeleton so it generates a new JSON, Great, we have a new JSON, we can clearly see that we have increased the size by more than twice.
So if you decide to use them make sure there are few vertices or don't bound the mesh to the bones. In general Maybe a few keys isn't a big deal but better to use them sparingly or not at all. A common mistake is when you go over all animations and adjust all meshes.
Just to patch things up. Don't do that. Cool, let's say we have decided to bind the mesh to bones, well, Before doing that it is important to understand where you will place the bones, especially for long attachments, such as rope, tail or hair.
Try to position a bone at the cross section of the triangles, that will improve bending. What's also important here is to weight vertices to the minimum number of bones necessary for the mesh to function. This allows us to modify bindings easely, and we will have less vertex transforms.
By binding a vertex to more than one bone we will increase the vertex transform count, which will increase the calculation time in your game. Calculations use CPU however it is relatively cheap, just keep an eye on it. It also means that you need to be mindful whenever you want to smooth the weights.
I normally hit once or twice. And instead of smoothening all vertices you can smoothen selected ones. Lastly, using prune may reduce a significant number of vertex transforms.
Oh and did you know that you can recalculate portions of the mesh for specific bones? So cool right? Great, we have our mesh bound to bones and working as expected.
What about the Clipping feature in Spine? I bet you heard that it is expensive, and according to the official documentation it is indeed a very expensive operation for the CPU. Always try to find alternatives before using the clipping feature.
For example you can make holes in the face to hide the pupils. Maybe add another image over it to hide the unwanted portion. However sometimes you might have no other option.
Like in this example, there is nothing I can hide the pupil behind. In those cases make sure the clipping mesh has the minimum vertices needed, clip fewest amount of attachments and avoid meshing clipped attachments, and even if you did mesh them, reduce the number of the vertices in each one as much as possible. And don't worry about the size of the clipping polygon; it does not affect the performance.
Just make them convex if possible because clipping attachment is first decomposed into convex polygons, then each resulting polygon is checked against all the clipped attachments. Cool, What if we want to fully hide some attachments? maybe the whole character?
If there are multiple attachments you might want to go and just scale root bone of the character down to 0 in one frame and boom it is gone. Just make sure you break the interpolation. Sure you can do that, just know that at runtime the character will be still sent to be drawn however nothing will be rendered.
And setting attachments to 0 transparency will still draw the image and use fill rate exactly the same way as if transparency was set to 100. So why not just hide the attachments? makes much more sense right?
What about Animation keys? How do they affect the performance? Well the keys just hold numbers, so more keys means bigger data files and more memory to hold the data at runtime.
For example this portion represents one key. And applying timelines uses some CPU, so fewer timelines is better. I personally never cut on timelines when I animate, I would even go and separate few timelines to have more control over them.
I would sometimes even go wild and animate frame by frame to perfect the motion. So this is another reason to rig with less bones possible. Less bones, fewer timelines.
And don't forget to clean up your keys when exporting for production. Next I would say don't use too many constraints but after double checking with Spine Developers, I can say that there is no real reason to avoid using constraints. Isn't it great?
But don't over do them though. Remember your rig should be flexible and functional to produce high quality animations in a reasonable amount of time. You don't need to show off by creating monster rigs full of constraints.
That was it for today. Subscribe to participate in the upcoming poll. Leaving a video on the screen with more tips.
Bye.