- Home /
When setting an array of (ShaderGraph) materials, only the first on is an instance?
Hi all,
I am using the URP and want to set a material that uses a Shader Graph dissolve shader to a renderer with multiple materials. This is my code:
var dissolveMaterials = new Material[originalMaterials[i].Length];
//Create a new array of materials of the length of the original materials, set all these to dissolve and give them the colour of the original material
for(int j = 0; j < dissolveMaterials.Length; j++)
{
dissolveMaterials[j] = dissolveMaterial;
dissolveMaterials[j].SetColor("Albedo", originalMaterials[i][j].color);
activeMaterials.Add(dissolveMaterials[j]);
}
//Set this new array
rendererList[i].materials = dissolveMaterials;
Where dissolveMaterials is the array with the dissolve shader material I want to set (with different colours).
My strange problem is, that while the materials and their colours are set, only the first material is (Instance), the other is shared... This is a problem, as this means I can't set individual colours or update the shader clip threshold of the not-Instance materials.
I have tried setting the dissolveMaterial with new or Instantiating it, but this doesn't help.
Does anyone know why only the first material is an Instance, or how I can get the others to become an Instance?
Thanks in advance!
Your answer
![](https://koobas.hobune.stream/wayback/20220613010730im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Shader Animation (and PerRendererData) 1 Answer
Unity Atlas shader Material is is changing the original material of objects 0 Answers
Fresnel shader and mixed textures 0 Answers
Holes in Occlusion Culling a transparent object 0 Answers
Dynamic batching breaks with the material Mobile/Alpha Blended. 0 Answers