Problem Description

I'm having an issue with Spine's SkeletonMecanim component in Unity. I implemented a "Create Unique Material Instance" option to allow each Spine object to use its own material instance, but the original material is still being used despite checking this option. It seems like SkeletonMecanim or SkeletonRenderer is forcefully overwriting my material instance during each update cycle.

Details
The issue occurs when trying to create a unique material instance for a Spine skeleton to modify its properties individually
Each frame, the original shared material is being reapplied, overriding any changes I make to the instance
I've found that SkeletonRenderer.LateUpdateMesh() calls meshRenderer.sharedMaterials = rendererBuffers.GetUpdatedSharedMaterialsArray() which seems to be overwriting the custom material instance
Questions
What would happen if I disable SkeletonMecanim component? Would it affect gameplay or animation behavior?

Are there any known side effects of modifying Spine materials at runtime?

Why does the original SkeletonMecanim implementation force a specific material to be used? Is this intentional for performance reasons or something else?

Is there an official way to create unique material instances for Spine objects without modifying the source code?

My Current Solution
I've modified the SkeletonMecanim class to override the LateUpdateMesh method and re-apply my material instance after the base implementation runs. It seems to work but I'd prefer to understand if there's a more proper way to achieve this or if there are any risks with this approach.

Any insights or official solutions would be greatly appreciated.****

Related Discussions
...

To address your issue with the SkeletonMecanim component in Unity, it seems that the SkeletonRenderer is indeed overwriting your custom material instance during each update cycle. This behavior is due to the LateUpdateMesh() method, which reassigns the shared materials to ensure that the correct materials are used for rendering based on the current attachments. This is intentional to maintain performance and ensure consistency across frames.

  1. Disabling SkeletonMecanim: Disabling the SkeletonMecanim component would stop the automatic updating of animations and materials, which would likely disrupt gameplay and animation behavior. The component is responsible for driving the animation state machine and updating the skeleton's pose.

  2. Modifying Spine Materials at Runtime: Modifying materials at runtime can lead to performance issues if not handled correctly, especially if new material instances are created frequently. It's important to manage material instances efficiently to avoid unnecessary garbage collection and performance hits.

  3. Forcing Specific Materials: The original implementation forces specific materials to ensure that the correct materials are used for rendering based on the current attachments. This is done for performance reasons and to ensure that the rendering is consistent with the skeleton's current state.

  4. Creating Unique Material Instances: The recommended way to create unique material instances without modifying the source code is to use the CustomMaterialOverride or CustomSlotMaterials properties provided by SkeletonRenderer. These allow you to override materials on a per-instance basis without affecting the shared materials. You can set these overrides in your script to apply your custom material instances.

Your current solution of modifying the SkeletonMecanim class to re-apply your material instance after the base implementation runs is a valid workaround, but it may not be the most efficient or maintainable approach. Using the CustomMaterialOverride or CustomSlotMaterials would be a more official and sustainable solution.

For more information, you can refer to the documentation on Changing Materials Per Instance.