I used the example project.
I also used the example code.

OptimizeSkin After doing it several times, at some point, when I OptimizeSkin, the skin breaks.

Or it gets blurry.

The spine file has many skins and has more than 13 materials. It's version 4.2.
ㅠ0ㅠ I can't solve the problem..ㅠㅠㅠ


MissingReferenceException: The object of type 'UnityEngine.Material' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Object+MarshalledUnityObject.TryThrowEditorNullExceptionObject (UnityEngine.Object unityObj, System.String parameterName) (at <2431722e3e3e41d78b6718bb39ab9111>:0)
UnityEngine.Bindings.ThrowHelper.ThrowNullReferenceException (System.Object obj) (at <2431722e3e3e41d78b6718bb39ab9111>:0)
UnityEngine.Material.GetFirstPropertyNameIdByAttribute (UnityEngine.Rendering.ShaderPropertyFlags attributeFlag) (at <2431722e3e3e41d78b6718bb39ab9111>:0)
UnityEngine.Material.get_mainTexture () (at <2431722e3e3e41d78b6718bb39ab9111>:0)
Spine.Unity.AttachmentTools.AtlasUtilities.GetMainTexture (Spine.AtlasRegion region) (at Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs:819)
Spine.Unity.AttachmentTools.AtlasUtilities.ToTexture (Spine.AtlasRegion ar, UnityEngine.TextureFormat textureFormat, System.Boolean mipmaps, System.Int32 texturePropertyId, System.Boolean linear, System.Boolean applyPMA) (at Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs:611)
Spine.Unity.AttachmentTools.AtlasUtilities.AddRegionTexturesToPack (System.Int32 numTextureParamsToRepack, Spine.AtlasRegion region, UnityEngine.TextureFormat textureFormat, System.Boolean mipmaps, UnityEngine.TextureFormat[] additionalTextureFormats, System.Int32[] additionalTexturePropertyIDsToCopy, System.Boolean[] additionalTextureIsLinear) (at Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs:477)
Spine.Unity.AttachmentTools.AtlasUtilities.GetRepackedAttachments (System.Collections.Generic.List1[T] sourceAttachments, System.Collections.Generic.List1[T] outputAttachments, UnityEngine.Shader shader, UnityEngine.Material& outputMaterial, UnityEngine.Texture2D& outputTexture, System.Int32 maxAtlasSize, System.Int32 padding, UnityEngine.TextureFormat textureFormat, System.Boolean mipmaps, System.String newAssetName, UnityEngine.Material materialPropertySource, System.Boolean clearCache, System.Boolean useOriginalNonrenderables, System.Int32[] additionalTexturePropertyIDsToCopy, UnityEngine.Texture2D[] additionalOutputTextures, UnityEngine.TextureFormat[] additionalTextureFormats, System.Boolean[] additionalTextureIsLinear) (at Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs:377)
Spine.Unity.AttachmentTools.AtlasUtilities.GetRepackedAttachments (System.Collections.Generic.List1[T] sourceAttachments, System.Collections.Generic.List1[T] outputAttachments, UnityEngine.Material materialPropertySource, UnityEngine.Material& outputMaterial, UnityEngine.Texture2D& outputTexture, System.Int32 maxAtlasSize, System.Int32 padding, UnityEngine.TextureFormat textureFormat, System.Boolean mipmaps, System.String newAssetName, System.Boolean clearCache, System.Boolean useOriginalNonrenderables, System.Int32[] additionalTexturePropertyIDsToCopy, UnityEngine.Texture2D[] additionalOutputTextures, UnityEngine.TextureFormat[] additionalTextureFormats, System.Boolean[] additionalTextureIsLinear) (at Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs:279)
Spine.Unity.AttachmentTools.AtlasUtilities.GetRepackedSkin (Spine.Skin o, System.String newName, UnityEngine.Shader shader, UnityEngine.Material& outputMaterial, UnityEngine.Texture2D& outputTexture, System.Int32 maxAtlasSize, System.Int32 padding, UnityEngine.TextureFormat textureFormat, System.Boolean mipmaps, UnityEngine.Material materialPropertySource, System.Boolean clearCache, System.Boolean useOriginalNonrenderables, System.Int32[] additionalTexturePropertyIDsToCopy, UnityEngine.Texture2D[] additionalOutputTextures, UnityEngine.TextureFormat[] additionalTextureFormats, System.Boolean[] additionalTextureIsLinear) (at Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs:550)
Spine.Unity.AttachmentTools.AtlasUtilities.GetRepackedSkin (Spine.Skin o, System.String newName, UnityEngine.Material materialPropertySource, UnityEngine.Material& outputMaterial, UnityEngine.Texture2D& outputTexture, System.Int32 maxAtlasSize, System.Int32 padding, UnityEngine.TextureFormat textureFormat, System.Boolean mipmaps, System.Boolean useOriginalNonrenderables, System.Boolean clearCache, System.Int32[] additionalTexturePropertyIDsToCopy, UnityEngine.Texture2D[] additionalOutputTextures, UnityEngine.TextureFormat[] additionalTextureFormats, System.Boolean[] additionalTextureIsLinear) (at Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs:521)
SpineSkinManager.OptimizeSkin () (at Assets/Scripts/Spine/SpineSkinManager.cs:101)
UnityEngine.Events.InvokableCall.Invoke () (at <2431722e3e3e41d78b6718bb39ab9111>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <2431722e3e3e41d78b6718bb39ab9111>:0)
UnityEngine.UI.Button.Press () (at ./Library/PackageCache/com.unity.ugui@22ebcc83720a/Runtime/UGUI/UI/Core/Button.cs:70)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at ./Library/PackageCache/com.unity.ugui@22ebcc83720a/Runtime/UGUI/UI/Core/Button.cs:114)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at ./Library/PackageCache/com.unity.ugui@22ebcc83720a/Runtime/UGUI/EventSystem/ExecuteEvents.cs:57)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at ./Library/PackageCache/com.unity.ugui@22ebcc83720a/Runtime/UGUI/EventSystem/ExecuteEvents.cs:272)

UnityEngine.EventSystems.EventSystem:Update() (at ./Library/PackageCache/com.unity.ugui@22ebcc83720a/Runtime/UGUI/EventSystem/EventSystem.cs:530)

    Related Discussions
    ...

    I think I know a little bit.
    OptimizeSkin();
    Inside
    Resources.UnloadUnusedAssets();
    This frequent use seems to result in this.
    I think I should use this function once the skin is confirmed.

      Gijun I used the example project.
      I also used the example code.

      OptimizeSkin After doing it several times, at some point, when I OptimizeSkin, the skin breaks.

      I could not reproduce the behaviour with the provided Mix and Match Skins example scene. Did you perhaps assign a different Material reference, or the one output from packing?

      Gijun Resources.UnloadUnusedAssets();
      This frequent use seems to result in this.
      I think I should use this function once the skin is confirmed.

      This should not result in anything bad like in the video you're showing. Are you using any special loading method like Addressables or loading from other resources or the like?

        Harald

        Copy and use 'Optimize Skin()' of the example script.
        The only thing I changed is maxTextureSize.
        (There are too many parts, so 2048 is not enough)

        Or just one part gets blurred, and then it turns pink at the end.

          Gijun Copy and use 'Optimize Skin()' of the example script.
          The only thing I changed is maxTextureSize.

          Then the problem might not lie within the copied part but in your code that combines the skins and calls OptimizeSkin().

          If you're sure that everything is correct on your side of combining skins, could you send us a minimal Unity project which still shows this issue? You can send it to contact@esotericsoftware.com, briefly mentioning this forum thread URL so that we know the context. Then we can have a look at what's going wrong.