In Prefab,We see that only two materials are assigned
But when I ran it, one of the materials had an extra copy, and the test found that the two materials took different parts of the same Texture. Causes skin level problems.
duplicates material in runtime
The issue you're experiencing with duplicated materials at runtime is likely due to the draw order requiring material switches, which can happen when different parts of a texture are used in separate draw calls. This is a common occurrence when attachments are spread across multiple atlas pages or when the draw order necessitates switching between materials. To address this, you can try the following solutions:
- Change Draw Order: Adjust the draw order to group attachments that use the same atlas texture together, minimizing material switches.
- Group Attachments: Organize attachments on atlas pages according to their draw order to reduce the need for switching materials.
- Pack Attachments: Aim to pack attachments into as few atlas pages as possible to reduce material duplication.
- Repack Skins: Consider repacking skins into a new atlas texture at runtime, which can help consolidate materials and reduce draw calls. This process is detailed in the Spine-Unity documentation.
These steps should help in reducing the number of materials used at runtime and improve performance by minimizing draw calls.
Sorry, the runtime view is this. However, the phenomenon is the same, there are duplicate materials.
duanxian0621 I think what you are encountering is exactly the situation described in the following section of the documentation: https://esotericsoftware.com/spine-unity-rendering#Material-Switching-and-Draw-Calls
As noted there, please pack attachments onto as few atlas pages as possible, and group attachments onto atlas pages according to the order of the drawings to avoid unnecessary material switching.
Misaki Misaki, thank you very much for your reply, but because we have many sets of skins, we split each skin into a Texture, as shown in the figure below, each skin corresponds to a material. When switching skins, you can switch to the corresponding material rendering. But the above problem occurred.
And I see that the SkeletonAnimationMulti in the Examples you provided also has a similar problem
duanxian0621 In that case, you may want to consider repacking skins as recommended by Spinebot. You can see how material can be put together by repacking skins in Assets/Spine Examples/Other Examples/Mix and Match Equip.unity
:
For more information on repacking, please see the following sections of the documentation:
https://esotericsoftware.com/spine-unity-main-components#Runtime-Repacking
Misaki Misaki, thank you for your solution. I have understood the principle and solved the problem. Thanks again.
duanxian0621 I’m glad to hear that! Thank you for getting back to us