• Unity
  • Dynamic Attachments Showing in Editor

Hi,

I have a script that does something similar to the mix-match demo and adds/swaps attachments dynamically. This all works great, but I'd like to take it a step further and be able to have the attachments shown in the editor, but the SkeletonRendererInspector seems to override the skeleton's skin every time my object is selected in the editor. Here is the code that overrides my skin:

if (!Application.isPlaying && Event.current.type == EventType.Layout) {
    bool mismatchDetected = false;
    if (multi) {
        foreach (var o in targets)
            mismatchDetected |= UpdateIfSkinMismatch((SkeletonRenderer)o);
    } else {
        mismatchDetected |= UpdateIfSkinMismatch(target as SkeletonRenderer);
    }

if (mismatchDetected) {
    mismatchDetected = false;
    SceneView.RepaintAll();
}
}

I can comment out UpdateIfSkinMismatch but I'm wondering if there is another way to get around this, maybe add my own inspector that updates the skin after the SkeletonRendererInspector?

Any help would be greatly appreciated.

Thanks!

Related Discussions
...

We are sorry for the inconvenience. Improving inspector code for easier integration with custom user editor code was on our mind for some time already, unfortunately due to important bugfixes we didn't get to it yet.

I have now created an issue ticket here for you to subscribe.
Note however, that we are going to integrate these editor changes on branches 3.8 and 3.9-beta, the 3.7 branch will not receive these modifications.

Great, thank you!

I was able to achieve pretty much what I wanted with a combination of subscribing to OnRebuild and setting the dynamic skin name to be the same as the initial skin name from the SkeletonAnimation component.

3 months later

Thanks for sharing, glad you could resolve it!

We hope to provide a more comfortable and intuitive way in the future to achieve this without the need for a workaround.


This problem has now been resolved via an additional SkeletonRenderer.EditorSkipSkinSync property for editor scripting.

As listed in the changelog as well:

  • Added SkeletonRenderer.EditorSkipSkinSync scripting API property to be able to set custom skins in editor scripts. Enable this property when overwriting the Skeleton's skin from an editor script. Without setting this parameter, changes will be overwritten by the next inspector update. Only affects Inspector synchronisation of skin with initialSkinName, not startup initialization.

You can download the updated unitypackages here as usual:
Spine Unity Download

Please let us know if any problems remain after this addition. Thanks for reporting this problem and contributing to its solution!