valorware

Hi,

I can add queued animations using AnimationState.AddAnimation(..), and the documentation says it adds this new requested animation to the current pile of queued animations. I cant find anywhere in the docs on how to actually clear that queue- all I can seem to find is setEmptyAnimation() and clearTrack(), both of which seem to end the CURRENTLY playing animation.

Just would like to know how to clear those queued animations please!

edit
I really can't find anything that does this, I have temporarily added my own function to AnimationState.cs which seems to work (safely i think.. maybe). My only concern at this point is if this is called during some mixing to the next state - is there any way I could get a confirmation on wehter this is safe to use or not, or if there is an official way?
public void ClearQueuedTracksForCurrentTrack(int trackIndex)
{
// Get current
if (tracks.Items[trackIndex] != null)
// Clear next
tracks.Items[trackIndex].next = null;
}
valorware
  • Posts: 9

badlogic

Sorry for the late reply! There is indeed no out of the box solution for clearing queued but not currently playing animations in the AnimationState API. Your work around will work, even for situations where one or more animations are mixed out with the current animation.

There's one issue not handled: the track entries that will be removed are supposed to be generating dispose events on removal:

spine-runtimes/AnimationState.java at 3.7

You are likely not seeing any ill effects due to this omission in your code, as the C# runtime has automatic memory management and you are unlikely to dispose related objects upon receiving a dispose event for each cleared track entry.

Thanks for pointing out this use case! We will add a full-blown implementation to the AnimationState API. I'll update this post with a link to the issue on the runtime issue tracker once we've identified all details.
User avatar
badlogic

Mario
  • Posts: 1720

badlogic

We've discussed this internally. Fetching the first item on a track and setting its next field to zero is the correct solution for all managed memory runtimes. Since this can be done with what we've exposed currently, there's no need to add an additional API to AnimationState.

For manually memory managed runtimes like C/C++, the linked list of track entries in the next field needs to be either reset and returned to the track entry pool (spine-runtimes/AnimationState.cpp at 3.7), or manually disposed.
User avatar
badlogic

Mario
  • Posts: 1720


Return to Unity