To address the issue you're encountering with CustomSlotMaterials
being empty, it's important to ensure that you're correctly assigning a new material to a specific slot at runtime. The CustomSlotMaterials
dictionary in SkeletonRenderer
allows you to replace the material for specific slots dynamically. Here's a basic example of how you can assign a new material to a slot:
// Assuming you have a reference to your SkeletonAnimation or SkeletonRenderer component
SkeletonRenderer skeletonRenderer = GetComponent<SkeletonRenderer>();
Material newMaterial = ...; // Your new material
string slotName = "your_slot_name"; // The name of the slot you want to change the material for
// Ensure the slot exists in your skeleton
Slot slot = skeletonRenderer.skeleton.FindSlot(slotName);
if (slot != null)
{
// Assign the new material to the slot
skeletonRenderer.CustomSlotMaterials[slot] = newMaterial;
}
else
{
Debug.LogWarning("Slot not found: " + slotName);
}
Make sure that the slot name you're using matches exactly with one of the slots in your Spine skeleton. If the slot name is incorrect or does not exist, the material will not be assigned, and the dictionary will appear empty when you check it.
If you're still facing issues, ensure that your newMaterial
is correctly set up and compatible with Spine's rendering system. Also, verify that you're using the latest version of the Spine Unity runtime compatible with your Spine Editor version, as there might have been fixes or changes related to material handling.