- Edited
Merging Update and LateUpdate
Greetings!
At the end of our project cycle, we are dealing with a large amount of SkeletonAnimation objects with very simple animations, so no IK or any of the advanced usage on those. What I noticed is that our hundreds of objects get iterated twice per frame due to Update and LateUpdate calls.
In an attempt to optimize this, I renamed the LateUpdate function to something else and manually invoked it at the end of Update. As result, the simple animating objects only get traversed once. We observed noticeable improvement in cpu usage due to limited cache size on the console platform. Animations seemed identical like before, well, with our limited testing.
My question is, what are the implications of such change? What's the reason the update code is separated into two passes in the first place?
Swordtwin Studios
As long as you weren't doing anything that needed to be between those two updates, it should be fine.
Update
basically updates the AnimationState and applies that state machine to the Skeleton.
LateUpdate
is actually the "generate mesh" method, and converts the abstract Skeleton state into a visible/renderable UnityEngine.Mesh.
If you were modifying and posing the skeleton after SkeletonAnimation's Update (by setting Script Execution Order manually), then the mesh generation code being called in LateUpdate ensures those changes are reflected in the visible mesh.
But if you were modifying and posing the skeleton using the provided events (UpdateLocal, UpdateWorld, UpdateComplete), it shouldn't matter either way. What you did was fine.
Thank you Pharan again for the explanation. We might have to investigate our code paths a bit more just to be safe.
Just leaving this link here for anyone else who might see this in the future: https://blogs.unity3d.com/2015/12/23/1k-update-calls/
It basically comes down to using array to update animations. Even with the manager approach, updating 10k gameobjects still has pretty bad cache usage due to unused/hidden fields in Monobehaviour classes being loaded to cache. We are already using arrays and vertices generation to some elements in our project, but as you might have guessed, not everything can be changed easily a few days from shipping. For the next project we might use the spine runtime only for main character animations.