Based on my knowledge of spine-unity's CustomMaterialOverride system, the issue you're experiencing after upgrading to 4.3 might be related to how materials are being applied or cached.
Here are a few things to try:
Force a material update
After setting or removing the material override, try forcing the renderer to rebuild its materials:
public void SetDefaultMaterial()
{
characterRenderer.CustomMaterialOverride.Remove(defaultMaterial);
characterRenderer.LateUpdate(); // Force material rebuild
}
public void SetHitMaterial()
{
characterRenderer.CustomMaterialOverride[defaultMaterial] = hitMaterial;
characterRenderer.LateUpdate(); // Force material rebuild
}
Verify the original material reference
Since you're caching the defaultMaterial in Awake(), make sure this reference is still valid. The way you're obtaining it should work, but you might want to verify it's not null and matches what's actually being used:
private void Awake()
{
defaultMaterial = characterAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial;
characterRenderer = characterAnimation.GetComponent<SkeletonRenderer>();
// Debug to verify the material reference
Debug.Log($"Default material: {defaultMaterial?.name}");
}
Alternative: Use CustomSlotMaterials
If the issue persists, you could try using CustomSlotMaterials instead, which targets specific slots:
private Slot targetSlot;
private void Awake()
{
defaultMaterial = characterAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial;
characterRenderer = characterAnimation.GetComponent<SkeletonRenderer>();
targetSlot = characterAnimation.Skeleton.FindSlot("yourSlotName"); // Replace with actual slot name
}
public void SetDefaultMaterial()
{
characterRenderer.CustomSlotMaterials.Remove(targetSlot);
}
public void SetHitMaterial()
{
characterRenderer.CustomSlotMaterials[targetSlot] = hitMaterial;
}
If none of these solutions work, could you verify that your materials are properly configured for the blend modes being used, and that both materials use the same shader parameters? The delay until animation change suggests the material system might be waiting for a rebuild trigger that's now happening at different times in version 4.3.