• Runtimes
  • Getting attachments from one Skin and setting them on a different Skin

Most of the time, I'm able to use code like this below to get an attachment from one skin and add it to another. Sometimes this doesn't work and I suspect it's because the skin I got the attachment from has extra data that the other skin does not. How can I get this extra data from the old skin and apply it to the new?

Here's a code example (Flutter) -

` spine.Skin _tempSkin = spine.Skin("temp-skin");

_tempSkin!.addSkin(data.findSkin('17_Sporty/17_Sporty_D_S_Upper')!);

slot = data.findSlot('ARM/Acces_ArmT/17_Sporty/D_S/Ribbon_1');

slotIndex = slot?.getIndex();

var att = _tempSkin?.getAttachment(slotIndex!, '17_Sporty/Upper_D_S/Ribbon_1');

_customSkin?.setAttachment(slotIndex!, '17_Sporty/Upper_D_S/Ribbon_1', att);`
Related Discussions
...

A skin is a simple map where the key is slot index + name and the value is the attachment reference. There is no extra data.

Attachments are stateless (see class diagram), they don't store any instance information like deform, etc. That information is instead stored on the slot, that way the same attachment can be in multiple skins or used by multiple skeleton instances.

The code you showed is fine. What doesn't work?

It does work for other attachments.

But this particular attachment doesn't show when I do it.

If I delete this attachment and copy it back onto the same skin, it works.

So that's why I thought the skin had some extra data not found on other skins.

Is there a visual debug setting so I can see all skins and attachments (as boxes or something)?

Here's the JSON:

{
"name": "17_Sporty/17_Sporty_D_S_Upper",
"bones": [ "Ribbon_1", "Ribbon_2", "Ribbon_3", "Ribbon_3b", "Ribbon_3c" ],
"physics": [ "Ribbon_2", "Ribbon_3", "Ribbon_3b", "Ribbon_3c" ],
"attachments": {
"ARM/Acces_ArmT/17_Sporty/D_S/Glove_L": {
"17_Sporty/Upper_D_S/Glove_L": {
"type": "mesh",
"uvs": [ 0.8632, 1.0E-5, 0.99991, 0.05625, 1, 0.15493, 0.67558, 0.61931, 0.61717, 0.93755, 0.11341, 0.99999, 0, 0.97905, 1.0E-5, 0.7737, 0.14091, 0.52055, 0.43063, 0 ],
"triangles": [ 3, 7, 8, 4, 7, 3, 5, 6, 7, 4, 5, 7, 2, 3, 9, 0, 2, 9, 2, 0, 1, 8, 9, 3 ],
"vertices": [ 1, 18, 38.72, 18.49, 1, 1, 18, 43.8, 45.18, 1, 1, 18, 67.2, 54.15, 1, 2, 18, 196.96, 45.12, 0.64674, 19, -1.8, 50.05, 0.35326, 2, 18, 275.98, 64.8, 0.01275, 19, 78.66, 62.58, 0.98725, 1, 19, 117.12, -15.01, 1, 1, 19, 117.23, -34.9, 1, 1, 19, 67.04, -49.11, 1, 2, 18, 205.84, -48.23, 0.12672, 19, -1.31, -43.72, 0.87328, 1, 18, 64.85, -49.78, 1 ],
"hull": 10,
"edges": [ 0, 2, 8, 10, 12, 14, 10, 12, 2, 4, 18, 0, 14, 16, 16, 18, 4, 6, 6, 8 ],
"width": 169,
"height": 254
}
},
"ARM/Acces_ArmT/17_Sporty/D_S/Glove_R": {
"17_Sporty/Upper_D_S/Glove_R": {
"type": "mesh",
"uvs": [ 0.7017, 0.19709, 0.99154, 0.32159, 0.99999, 0.64991, 0.83761, 0.99999, 0.589, 0.95635, 1.0E-5, 0.8141, 0, 1.0E-5, 0.24167, 0 ],
"triangles": [ 4, 0, 3, 2, 0, 1, 2, 3, 0, 5, 7, 4, 4, 7, 0, 5, 6, 7 ],
"vertices": [ 2, 22, 185.59, 31.88, 0.77141, 23, -9.76, 30.59, 0.22859, 2, 22, 261.27, 19.79, 3.3E-4, 23, 64.1, 51.05, 0.99967, 2, 22, 265.26, -20.78, 0, 23, 84.6, 15.81, 1, 2, 22, 225.18, -66.02, 0.05323, 23, 66.94, -41.99, 0.94677, 2, 22, 160.61, -63.48, 0.66035, 23, 7.16, -66.52, 0.33965, 2, 22, 7.43, -52.64, 0.8, 21, 328.16, -22.32, 0.2, 2, 22, 2.94, 48.2, 0.8, 21, 242.11, 30.45, 0.2, 2, 22, 65.47, 50.99, 1, 23, -126.95, -1.96, 0 ],
"hull": 8,
"edges": [ 4, 6, 12, 14, 2, 4, 8, 10, 2, 0, 0, 14, 6, 8, 10, 12 ],
"width": 259,
"height": 124
}
},
"ARM/Acces_ArmT/17_Sporty/D_S/Ribbon_1": {
"17_Sporty/Upper_D_S/Ribbon_1": {
"type": "mesh",
"uvs": [ 0.99999, 0.24721, 0.97983, 0.52731, 0.77859, 0.81189, 0.64557, 1, 0.54156, 0.99999, 0.3595, 0.72923, 0.39643, 0.4657, 0.47162, 0.2958, 0.29446, 0.36659, 0, 0.19266, 0, 0.09296, 0.23057, 0, 0.795, 0, 0.68771, 0.08382 ],
"triangles": [ 3, 4, 2, 4, 5, 2, 2, 5, 1, 5, 6, 1, 6, 7, 1, 1, 7, 0, 7, 13, 0, 8, 9, 7, 9, 11, 7, 7, 11, 13, 9, 10, 11, 13, 12, 0, 13, 11, 12 ],
"vertices": [ 2, 570, 20.29, 34.46, 0.99632, 571, -41.48, 34.46, 0.00368, 2, 570, 79.35, 37.78, 0.08638, 571, 17.58, 37.78, 0.91362, 2, 571, 79.76, 19.02, 0.03939, 572, 17.99, 19.02, 0.96061, 1, 572, 59.09, 6.62, 1, 1, 572, 60.34, -6.11, 1, 2, 571, 67.45, -33.99, 0.42362, 572, 5.68, -33.99, 0.57638, 4, 569, 62.45, 60.84, 0.00891, 570, 73.44, -34.91, 0.1582, 571, 11.67, -34.91, 0.83285, 572, -50.1, -34.91, 4.0E-5, 3, 569, 37.2, 33.76, 0.44091, 570, 36.86, -29.21, 0.50171, 571, -24.91, -29.21, 0.05738, 3, 569, 63.48, 36.47, 0.87824, 570, 53.86, -49.44, 0.12172, 571, -7.91, -49.44, 4.0E-5, 1, 569, 77.77, -13.07, 1, 1, 569, 67.72, -31.55, 1, 1, 569, 33.43, -35.24, 1, 3, 568, -15.83, 13.35, 0.90787, 569, -27.56, -2.08, 0.03179, 570, -29.15, 4.26, 0.06034, 3, 568, 1.14, -0.75, 0.91841, 569, -7.51, 7.16, 0.04535, 570, -10.26, -7.14, 0.03624 ],
"hull": 13,
"edges": [ 0, 24, 0, 2, 6, 8, 8, 10, 14, 16, 16, 18, 18, 20, 20, 22, 22, 24, 10, 12, 12, 14, 2, 4, 4, 6 ],
"width": 123,
"height": 211
}
},
"ARM/Acces_ArmT/17_Sporty/D_S/Ribbon_2": {
"17_Sporty/Upper_D_S/Ribbon_2": {
"type": "mesh",
"uvs": [ 0.02856, 0.63909, 0, 0, 1, 0, 0.91605, 0.72362, 0.8034, 0.99999, 0, 0.85685 ],
"triangles": [ 4, 5, 3, 5, 0, 3, 3, 0, 2, 0, 1, 2 ],
"vertices": [ 3, 18, -36.87, -48.95, 0.01743, 17, 216.82, -35.99, 0.97738, 25, 235.53, -44.78, 0.00519, 2, 17, 77.19, -45.89, 0.00804, 25, 95.63, -40.04, 0.99196, 2, 17, 72.44, 44.99, 0.99314, 25, 100.4, 50.84, 0.00686, 2, 18, -48.46, 33.09, 0.10136, 17, 231.1, 45.63, 0.89864, 2, 18, 11.73, 45.15, 0.89495, 17, 292.07, 38.55, 0.10505, 2, 18, 8.59, -34.33, 0.47122, 17, 264.58, -36.1, 0.52878 ],
"hull": 6,
"edges": [ 2, 4, 6, 8, 8, 10, 4, 6, 2, 0, 0, 10 ],
"width": 91,
"height": 219
}
},

Ribbon 2 works, but not Ribbon 1.

Ribbon 1 works only if I copy the attachment from the same skin to another copy of the same skin (that I've already deleted the attachment from prior)

Okay, I figured it the problem. The skin that I took the attachment from had bones and physics that the skin I applied the attachment to didn't have.

So is the solution just add all bones and physics to all skins that can use the same attachments?

Or is there a way to copy bones and physics to a skin using code, when I need them?

Ah that's right, sorry! Skins are a map but also have a list of bones and constraints. You'll need to add them to the other skin if they are needed.

Does it make sense to attach bones and physics at the attachment level?

That way each attachment is responsible for itself?

  • Đã chỉnh sửa

No, that doesn't make sense. There is a single list of bones and constraints for a skin. They are not necessarily for any particular attachment.

You can add all the attachments, bones, and constraints from one skin to another. If you want to copy just some attachments, you'll need to know which bones and constraints are also needed to add to another skin (if not all of them).