@devis.rossini
Sorry it took me forever to get back to you. I've been a bit busy.
Turns out, the quick fix is easier than I thought. I can only imagine Nate did this on purpose.
So here goes:
Search for the file Animation.cs
in the Spine runtime in your project. It should be under spine-csharp but you can just use the search in your IDE or project view.
Look for the AttachmentTimeline
class. Then look at its definition for the Apply
method. (You're looking for the AttachmentTimeline.Apply
method)
Look for the lines that say:
int frameIndex = (time >= frames[frames.Length - 1] ? frames.Length : Animation.binarySearch(frames, time)) - 1;
if (frames[frameIndex] < lastTime) return;
String attachmentName = attachmentNames[frameIndex];
skeleton.slots.Items[slotIndex].Attachment =
attachmentName == null ? null : skeleton.GetAttachment(slotIndex, attachmentName);
These are the lines that search for the appropriate key in the data, and apply it.
The line if (frames[frameIndex] < lastTime) return;
is the line that causes AttachmentTimelines to behave like EventTimelines (applying attachments only when time passes though the keyed time).
HERE'S WHAT YOU WANT TO DO. Comment that line out:
//if (frames[frameIndex] < lastTime) return;
The AttachmentTimeline will behave more like a stepped graph (which gets applied every frame and can override changes of lower animation tracks).
Performance considerations:
Note that this does incur an cost every frame for every slot you have keyed in every Spine.Animation you apply:
AttachmentTimeline passes through Skeleton.GetAttachment which uses Skin.GetAttachment which does a Dictionary lookup to find the attachment.
That said, if it's just for the main character, of maybe even a few, it's probably not something you should even worry about.
In this case, try not to key slot attachment changes for skeletons that number in... I dunno... maybe hundreds... in your scene.
In fact, just as a general guideline even without this change, if have a lot of that skeleton animating in the scene, don't key anything that doesn't need animating.
Future stuff:
Nate's been thinking about a cleaner fix for this. (that achieves both the performance benefits, and the ability to override attachment timelines)
I thought of a solution but it architecturally wasn't as clean as either of us would like to stick in the main runtime.
On my end, it's also an untested idea so there may be unconsidered parts that make it not a sensible option at all.