- Edited
Optimisation Tips (Nintendo Switch + General)
Hi guys! I'm currently on working on optimising a Unity project which makes use of a lot of spine animations for various enemies and player characters. It all works fine on PC but when I'm running on the Nintendo Switch I'm finding that there's a big performance hit each time a new Spine Skeleton Graphic is enabled for the first time. Once they're all there and running the performance is fine.
I'm loading one of the worst offending objects asynchronously in the background, which works beautifully but the first time it actually gets turned ON the whole device just freezes for over 30s. It takes less than half of this without the Spine Skeleton Graphics present (obviously less resources = quicker set-up in general, but they're taking up the bulk of the set-up time and only account for a small number of the component parts of the overall object).
I was just wondering if anyone here had any advice or tips for improving the initial set-up performance (particularly on the Nintendo Switch, but also in general)?
[..] freezes for over 30s. It takes less than half of this without the Spine Skeleton Graphics present
Freezing for less than half of 30s without Spine assets still sounds very bad in general - I strongly suggest to analyse the general setup and then carry on with Spine-specific optimizations.
I recommend taking a look at Unity's built in profiler first in order to identify the bottleneck there - which method calls are taking very long, garbage collection hickups, etc. If your setup freezes for 10 seconds you should find something suspicious in the profiler, even on PC.
If I may add, check if the spine object in question uses many vertices and mesh deformation keys (you can see this by opening the metrics view in the Spine editor). If yes, consider optimizing the file as well, by removing unnecessary vertices, and trying to deform the mesh by weighting them to bones instead of directly deforming them. Especially for meshes with many vertices and/or bones per vertex.
Thanks @Erikari for the additions.
Maybe some additional general optimization hints:
- Use as few materials as possible (equals as few textures as possible, pack them to shared atlases where possible). This keeps the number of drawcalls lower. However consider that manually triggering baking of atlases at runtime via code (e.g. after your bulk of Spine objects gets loaded/streamed) is a costly operation, so you might want to pre-pack them via the Spine Editor, or pack them while loading a bigger bulk of assets while showing a loading screen or similar.
- Use as few vertices as possible.
- Use as few GameObject nodes as possible - a very deep hierarchy with many GameObjects per character can have a very noticable impact on performance.
- Use pools of objects (and pre-warm the pool) and reuse them where possible, instead of instantiating prefabs. Enabling objects and re-positioning them should in general be much faster than instantiation.