• Runtimes
  • How do you hide an attachment at runtime?

Related Discussions
...

I've looked all over in the docs for how to do this. I can get an attachment by name just fine, but don't see a way to hide it programmatically (Widget runtime).

Let me take a step back and quickly outline how the skeleton hierarchy works. A skeleton is composed of one or more bones. A bone may have zero or more bone children. A bone may also have zero or more slots. Slots are locations in a skeleton to which attachments can be attached and thus made visible. A slot can only have a single attachment attached at a time.

So, to make an attachment invisible, you have to find the slot it is attached to, and then set the attachment on the slot to null. Assuming you know the slot the attachment is attached to, it's as simple as:

skeleton.findSlot("slotName").setAttachment(null);

Note that calling skeleton.setToSetupPose, skeleton.setSlotsToSetupPose, skeleton.setSkin as well as having attachment timelines may attach the attachment to the slot again.

Ahhh that's how! Got it. Thank you!

3년 후

For someone having problems with this in Unity, it should be like this. Maybe the API changed since 2.5 years 🙂

skeleton.SetAttachment("slotName",null);

Actually the above code is still valid (your line is a shortcut), although the spine-csharp (and thus spine-unity) API looks a little bit different than the other runtimes, as it uses properties instead of setter methods. And an uppercase first letter, as is the convention there:

skeletonRenderer.skeleton.FindSlot("name").Attachment = attachment;

Please also consider having a look at the Spine Examples directory before searching the forum, such basics are all covered there with lots of example code to check out.