In order to improve performance in my game I've edited SkeletonAnimation to not perform an Update when an object is off-camera:
void Update() {
#if UNITY_EDITOR
if (!Application.isPlaying) {
Update(0f);
return;
}
#endif
if (meshRenderer.isVisible) {
Update(Time.timeSinceLevelLoad - lastUpdateAt);
lastUpdateAt = Time.timeSinceLevelLoad;
}
All fine and good. With one exception! I'm using Spine Events to trigger certain things at the right time in an animation, but those Events won't get processed if the Timeline.Apply(...) never gets called by an Update(deltaTime) that never happens. A character wanders off camera and begins to perform some action which would ordinarily call some event, but because meshRenderer.isVisible != true the events never surface and the character gets stuck.
I am wondering - is there a customisation I can make to the Spine Unity runtime that allows for an Update that isn't so performance heavy, ie; all it does is process Event tracks in an animation? I'm not very familiar with the guts of the runtime to know if that's an easy thing to do, or just an uphill battle against Spine's core design.
Perhaps I'm tying too much critical logic into the animations themselves, but events are such a workflow-friendly way of timing things to an animation! And I care about that timing when these characters are on camera. I should very much like to not update my animations when a character is off-screen... but also listens to events.
What would be the right solution for me here, maintaining performance and my existing event-based logic?