Hi all, I have an animated character in my game that takes a shield component and I’m trying to change from the original material (Mobile/Unlit), to the new shield material (Mobile/Particles/Additive). I’m doing it like this:
public class MaterialChanger : MonoBehaviour {
public Material shieldMaterial;
private Material originalMaterial;
void Start () {
originalMaterial = renderer.material;
}
void Update () {
if (Input.anyKeyDown) {
if (renderer.material == originalMaterial)
renderer.material = shieldMaterial;
else
renderer.material = originalMaterial;
}
}
}
I have isolated the problem into a simple scene, containing my character (with a SkinnedMeshRenderer component), and a simple cube (with a MeshRenderer component), and I have attached the script to both of them.
Well, the material update only works for the cube, but not for the character. The material is stored in an Assets/Materials folder, and I have just dragged it to the script via unity interface.
I don’t know what I’m doing wrong, but the truth is that it randomly works in the Editor, sometimes only in Android, and some others only in iOS.
My guess is that there is a fatal combination between SkinnedMeshRenderer and this particular shader (Mobile/Particles/Additive), because changing to a Mobile/Unlit works perfectly.
I have dedicated a lot of hours to this issue, and I’m assuming I won’t be able to use this shader in the game. Any ideas? Any other test I could make to discard options? Thanks in advance, Robert.