• RuntimesUnityBugs
  • [Unity] Spine animation conflicting with updating material instance

Our game is a city building where you can pick up objects to move them around.

When you pick up an object, we animate the material's tint colour to have a flashing effect that indicates the object is picked up. We are using the Skeleton Tint shader, and updating the "_Color" property to do this.

This mostly works well. When I pick up most objects the material changes to an instance material and the colour tinting happens properly.

However, for some objects that animate the material is constantly swapping back and forth between the instance material and the shared material, which breaks the tinting. I've tried forcing it to stay as the instance material in several ways, but it seems like something on Spine's side is forcing it back to the shared material, and this seems directly related to the animation in some way.

Is there something that would cause that behaviour?

I've uploaded a video showing how the material is swapping when the object is picked up

Thanks!

Related Discussions
...

In subsequent testing we have been able to resolve the issue by removing all instances of toggling any images on/off within the animation.

This isn't a great solution because our animations toggle images on/off all the time, but I hope this provides further insight into a solution.

@arcbox Could you please show the code you're using to set the Material _Color property? Please see the following spine-unity documentation section, likely you want to use MaterialPropertyBlock instead of your way:
https://esotericsoftware.com/spine-unity#Changing-Materials-Per-Instance

Sure, I'm just using the Material.SetColor method, as follows:

mat.SetColor("_Color", Color.white)

And I'm calling that function in a tween where the brightness of the color is adjusted to produce the glowing effect:

DOTween.To(x => mat.SetColor("_Color", Color.white.AdjustBrightness(x)), 1, 0.8f, 0.75f)

Is that problematic?

@arcbox What is missing from your code above is how you're getting and assigning the material mat, but I assume that you're using something like MeshRenderer.material which creates material duplicates. Please see the documentation on Materials why that is problematic:
https://esotericsoftware.com/spine-unity#Materials

As mentioned before, please see the following section what to do instead:
https://esotericsoftware.com/spine-unity#Changing-Materials-Per-Instance