DarkTI

Let's say we have an animation that sets a few attachments, which looks like this in json:
"animations": {
"attack_01_end": {
"slots": {
"hand_r": {
"attachment": [
{ "name": "chibi/hand_r_04" }
]
},
"mouth": {
"attachment": [
{ "name": "chibi/mouth_open_01" }
]
}
...
Is there a way to make the runtime ignore one of these attachments when we use this animation? For example, let's say we want "hand_r" slot to be ignored by runtime when we use this animation, while "mouth" slot still should work.

Or, if it's impossible, is there a recommended way to overwrite the unneeded slot attachment every frame?
Аватара пользователя
DarkTI
  • Сообщения: 22

Jamez0r

What is it that you're trying to use this for? Sounds like you have an animation that under normal circumstances would switch out the attachment, but under some special conditions you don't want the hand_r slot to get swapped out? I'm wondering if you could use a Skin to achieve the desired result, but would need to know more info.
Аватара пользователя
Jamez0r
  • Сообщения: 259

Harald

Thanks again Jamez0r for chiming in! :)

@DarkTI Unfortunately I'm not quite sure what you're trying to achieve. Note that if your animations overwrite attachment state, then you could still use one of the SkeletonAnimation Update Callbacks to disable or re-enable some attachments after the animation has been applied.
Аватара пользователя
Harald

Harri
  • Сообщения: 2778

DarkTI

In short, sometimes editing animations in spine editor requires to apply different hairstyles to animation to check how they behave after the animation was edited. And occasionally artists forget to remove the applied hairstyle, which leads to animation enforcing this hairstyle needlessly, ignoring slots overwrites done via code.

Of course it can be fixed by reporting about this issue to the artist, or by manually editing the json (which I'd like to avoid), but it would be faster to bypass this issue for hairstyles slots (and only for them) once and for all. Since we will never need animations to enforce certain hairstyles anyway.

At first I hoped to edit animations during runtime to remove unneeded attachments from them, but seems like API doesn't support such things.
So currently I solved it via editing spine importing code, replacing
if (timelineName == "attachment") {
var timeline = new AttachmentTimeline(values.Count);
timeline.slotIndex = slotIndex;
by
if (timelineName == "attachment") {
if (!slotName.Contains("hair")){
var timeline = new AttachmentTimeline(values.Count);
timeline.slotIndex = slotIndex;
in SkeletonJson.cs. The only drawback of this is that I will need to edit it again after spine runtime update :)
Аватара пользователя
DarkTI
  • Сообщения: 22

Jamez0r

If you make your hairstyles each into their own skin, then your animators can switch the skins in Spine and test all of them out to make sure they look good (without anything being "keyed" in any animation, which is what it sounds like is happening with the attachments).

The skin configuration that is active in Spine isn't applied to the exported character, so as long as you set up your programming to set the skin configuration (aka setting the skins for hair, face, clothes, whatever) as desired, you should be good to go!
Аватара пользователя
Jamez0r
  • Сообщения: 259

Harald

Jamez0r's suggestion is the cleanest solution. Don't let your artists create faulty data that is later "bent in place" to perform correctly.

If you really want to clean up faulty data, then two more options would be:
1. Writing a shell script / python script that automatically removes the respective lines from a json file
2. Better: writing a Skeleton Data Modifier Asset.

Bear in mind that anything operating on .json skeleton files will not work if you should later switch to binary export of .skel.bytes files for faster loading.
Аватара пользователя
Harald

Harri
  • Сообщения: 2778

DarkTI

Oh, I'd love to use Skeleton Data Modifiers. It's the first thing I tried. But I found no way to edit SkeletonData to remove unneeded attachments keys after they were imported from json. Or rather, I found no way to edit animations timelines at runtime at all.

But using skins is a good idea too, I agree.
Аватара пользователя
DarkTI
  • Сообщения: 22

Harald

DarkTI писал(а): Or rather, I found no way to edit animations timelines at runtime at all.
You would have to iterate over all skeletonData.Animations.Timelines, then check if (timeline is AttachmentTimeline), then modify the timeline as AttachmentTimeline accordingly. Admittedly modifying the frames is not completely user-friendly, but you basically need to remove each undesired entry pair from both attachmentTimeline.Frames[removalIndex] and from attachmentTimeline.AttachmentNames[removalIndex]. It should not be too complicated, but if you need further help, just let us know.
Аватара пользователя
Harald

Harri
  • Сообщения: 2778

DarkTI

An attempt to edit attachmentTimeline.Frames and attachmentTimeline.AttachmentNames led to index out of range somewhere in spine code when using the animation in question.

So instead I did this: checked if timeline is AttachmentTimeline, then checked if any of AttachmentTimeline.AttachmentNames contain unneeded attachments, and if yes then removed the whole timeline from skeletonData.Animations.

Works well for our setup, removes only the unneeded part. Thanks for the advice, I'd never guess to use
as AttachmentTimeline
on my own :)
Аватара пользователя
DarkTI
  • Сообщения: 22

Harald

Glad you've figured it out, thanks getting back to us. :)
Аватара пользователя
Harald

Harri
  • Сообщения: 2778


Вернуться в Unity