• RuntimesUnity
  • How to disable attachment for specific SkeletonAnimation from code?

Hi, my skeleton has item in hand by default I would like to disable it without copying and modifying SkeletonDataAsset.
The only solution I found is this, but I'm not sure how correct it is, seems hacky. Should I use it or there are "better/safer" ways to do that:

private Attachment _attachment;
        
[Button]
public void EnableSlot()
{
    var slot = _skeletonAnimation.Skeleton.FindSlot(_slotName);
    if (_attachment != null)
        slot.Attachment = _attachment;
}

[Button]
public void DisableSlot()
{
    var slot = _skeletonAnimation.Skeleton.FindSlot(_slotName);
    if (slot.Attachment != null)
        _attachment = slot.Attachment;
     slot.Attachment = null;
}
  • Harald ответили на это сообщение.
    Related Discussions
    ...

    lekret Hi, my skeleton has item in hand by default I would like to disable it without copying and modifying SkeletonDataAsset.

    It would be horrible workflow if copying of the shared SkeletonDataAsset would be required. Obviously it's better to modify the active attachments of the skeleton (the instance) only instead.

    Please check out the documentation here on Data vs Instance objects:
    http://esotericsoftware.com/spine-runtime-architecture#Data-objects
    http://esotericsoftware.com/spine-api-reference#API-Reference
    After you're familiar with the difference between instances vs shared data, you might want to have a look at the spine-unity documentation here:
    https://esotericsoftware.com/spine-unity#Skeleton
    Also check out the many example scenes that come with the spine-unity runtime, to be found under Spine Examples/Getting Started and Spine Examples/Other Examples.

    • lekret ответили на это сообщение.

      Harald I know the difference between data and instances. I also checked the links, but couldn't find any exact info with examples. So, is the code I've shown correct? Correct I mean stable and intended way to do it?

      • Harald ответили на это сообщение.

        lekret I know the difference between data and instances.

        Ok, your sentence regarding copying SkeletonDataAsset made us think that you didn't know that yet.

        I also checked the links, but couldn't find any exact info with examples. So, is the code I've shown correct? Correct I mean stable and intended way to do it?

        Yes, your code is using a correct way of setting and clearing attachments.