I'm afraid there's currently no way to persist an animation state in any of our runtimes out of the box. We have an open issue for it on the issue tracker on GitHub:
https://github.com/EsotericSoftware/spine-runtimes/issues/1185
This is an old issue, and we have since prioritized other things, also because the problem at hand is pretty complex to get working in 100% of cases.
The basic idea would be to serialize/deserialize all spTrackEntry
instances the spAnimationState
holds in its tracks. The serizalization of track entries is not too complex. For each track, fetch the current entry via spAnimationState_getCurrent()
, then serialize that track entry and the chain of entries pointed to via its previous
, next
, mixingFrom
, mixingTo
, and timelineHoldMix
fields. Track entries can also point to callback functions (listeners). You'll have to find a way specific to your project how to serialize/deserialize those.
Deserialization would then reestablish those track entries in an "empty" animation state. On the surface, this also not super complex, but we currently lack functions for animation state that let you create and setup your own track entries without going through spAnimationState_setAnimation/addAnimation
. You can directly modify spAnimationState.tracks
and spAnimationState.tracksCount
for the time being.