Solgryn

What I want to achieve is resetting all attachment images to their default whenever a new animation starts. Because I don't key all of them in all animations as it would be inefficient, when transitioning between two animations, the target animation will use the wrong attachment images (for example, the body would be turned, when it's supposed to be straight).

A solution i've found is to make an animation called "resetAttachments" or so, and every time I transition to a new animation, I load that animation into the state. The animation contains keys for all attachments in their default state. It seems kind of sloppy, and I'd have to make that same animation for all the characters, and whenever I add a new attachment image to the skeleton.

Is there a way to reset all attachment images via code to their default (as they appear in the pose editor in Spine)? Maybe a way to only change those that aren't in the default state already.
Аватара пользователя
Solgryn
  • Сообщения: 45

Pharan

This is what skeleton.SetSlotsToSetupPose() does.
It also resets draw order. But it sounds like that would work fine in your case.
You could also use skeleton.SetToSetupPose() to exactly match how the editor doesn't inherit poses between animations.


If, for some reason, you just want to reset attachments and don't want it to reset the draw order, you may have to set up your own method that does:
public static void SetSlotsToSetupPoseButNotDrawOrder (Skeleton skeleton) {
var slots = skeleton.slots;
for (int i = 0, n = slots.Count; i < n; i++)
slots.Items[i].SetToSetupPose(i); // this also resets slot colors
}
Аватара пользователя
Pharan
  • Сообщения: 5366

Solgryn

Nice, thanks for the in-depth answer c:

-- 26 Mar 2016, 01:22 --

I'm having an issue where attachments are still being changed from the old animation when transitioning into a new animation.
It makes sense, but I'm wondering if there's a way to only to change attachment images from the new animation? Didn't realise this is the problem I was having.

For example, my character is running, and transitioning into idle. I change the body image in the very start of idle, but while transitioning, the run animation changes some attachments, and the result is the idle animation mixed with some of the run animation. I'd want it to only count the attachment changes from idle.
Аватара пользователя
Solgryn
  • Сообщения: 45

Pharan

Ah. There's a number of possible fixes for that.

If you are using mixing.
One I can think of is to comment out this line from Animation.cs (if you want the next animation to reliably override attachments from the previous animation)
https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-csharp/src/Animation.cs#L451
That step makes attachments be applied every frame instead of only when time passes over the key (like events).

And then probably add this in its place
const float alphaThreshold = 0.5f; // don't set the attachment below 0.5 alpha.
if (alpha < alphaThreshold) return;
Аватара пользователя
Pharan
  • Сообщения: 5366

Solgryn

That seems to work! c: Thank you.

Now whenever I update the runtime in the future, I'd have to comment out the line every time I imagine. Are there any plans to maybe add a setting for it in unity somehow? To me it seems much more desireable when mixing between animations, but I guess it's less optimized.

Anyway, thanks for the help c:
Аватара пользователя
Solgryn
  • Сообщения: 45

Pharan

There's an update to AnimationState and Animation systems coming to all runtimes and that's part of it.
But for the next few updates until that one gets applied, yeah, you have to do that.
Аватара пользователя
Pharan
  • Сообщения: 5366


Вернуться в Unity