- Edited
CustomSlotMaterial vs Submeshes?
We have a character in our game that has a mask with a few slots on it, along with the rest of the skeleton for said character. We plan on doing some mesh deformations and animations on the mask, so it's important that it's all part of the same spine project and not separated or hooked up at runtime.
We would like the mask and the rest of the body to have two different shaders.
My plan was to create a submesh for the mask, and apply a separate material for that mesh, rather than using the CustomSlotMaterial for all the given slots being used for the mask. Are there any issues with this approach that I should be considering?
Also, I'm sure I'll find this out when we try, but I'll preemptively ask anyway: will setting a material of a submesh be overwritten by the runtime?
Yes, submesh materials are managed by Spine's code (any manual changes will be overwritten) because each submesh could be comprised of any collection of attachments, which may use a specific Materials.
What material it uses is stored in the Attachment objects themselves.
If these mask images will ALWAYS use a different shader, you can just change the Material reference stored in each of the relevant Attachments. You can do this at load time after the skeleton data has loaded.
You must find all the references to the relevant attachments.
You can get their references either on their slots, or in the skeleton's default/active skin.
Then you can use this method:
static void SetMaterial (List<Attachment> attachments, Material replacementMaterial) {
var page = new AtlasPage {
name = replacementMaterial.name,
rendererObject = replacementMaterial
};
foreach (var a in attachments) {
var ra = a as RegionAttachment;
if (ra != null) {
((AtlasRegion)ra.RendererObject).page = page;
continue;
}
var ma = a as MeshAttachment;
if (ma != null) {
((AtlasRegion)ma.RendererObject).page = page;
continue;
}
}
}