colinday

  • 8 Th06 2016
  • Đã tham gia 25 Th09 2013

    @colinday: At your level, if something mysterious and unexplained happens, a cursory look at the classes and the calls are usually enough to explain things. Not blaming you or anything! Just saying, it's what I've been doing this whole time, and being developers, it's empowering to be able to read and edit the code (as it should be)
    https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-csharp/src/Skeleton.cs#L241

    SetSkin does two separate things depending on whether Skeleton.skin is null or not, or if there wasn't a skin assigned already.

    If there wasn't a skin assigned, it calls Skin.AttachAll()
    At this point, you should know that the Skin object is a dictionary/map of slot+attachment names and attachments.
    It will go through all the items in the skin, and changing the slots based on what items exist in the Skin.

    If there was already a skin assigned, it iterates through all the slots in that Skeleton.
    At this point, it's a bit strange. (And you can absolutely change the code here depending on what you need).
    For each slot, it takes the name of the attachment it's supposed to have in Setup Mode. (slot.data.attachmentName)
    If the slot is empty in Setup Mode, it'll do nothing.
    If the slot has a name in setup mode, it will try to get an attachment from the skin.
    If the skin doesn't have an attachment for it, it will do nothing. (at this point, what you want is probably set it to null instead of doing nothing)
    If the skin has an attachment for it, it will use that.
    Then it will store the reference of the newly set skin object in the skeleton.skin field, so it will be used by animations going forward.

    The fix
    The change you want is likely on this line: https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-csharp/src/Skeleton.cs#L252
    Just remove the if conditional so it'll change the attachment even if it's null.
    Similar logic can be found here: https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-csharp/src/Skin.cs#L84
    But I don't know if you need to change that.

    I think what these lines are trying to avoid is clearing an attachment in case you programmatically set that attachment yourself. I've always found the manual low-level setting of attachments at runtime to be flimsy. Any animations you play could easily change them. So I do everything through dynamically generated skins.

    Many of the "weird" things Spine does is based on some amount of ambiguity, which is why this feedback is useful if something doesn't make sense in your use case, if you feel like your setup is the most common, or if there could possibly be other setups too. This informs the development process, and fix bugs if it's a bug.

    Skins are definitely an area for improvement for both the runtime and the editor: support for mix and match, multiple skin combinations, etc.

    @colinday What makes you think Spine does this?

    Also, I haven't noticed it break in 5.2.