Hello, I’ve been trying for few hours to use a shared material.
I have a parent GameObject that creates instances of hundreds of landscape patches. I want these patches to share the same material and change shader variables and texture values in the Update function of each patch.
I don’t wanted hundreds of different materials because I want to edit the material in-game and see the changes happen to all the patches at once.
I’ve make a material in the parent object and each patch references that material by setting renderer.sharedMaterial to that parent material. But it doesn’t seem to work as it’s not setting texture values correctly for each instance.
My question is, is this the correct way to do this, and is there a more standard way of sharing a single material among many objects.
Thanks,
Dave.
So to help my confusion, does the rendering process go something like this?
- Call all Updates on game objects.
- Render all the meshes
or does it:-
- Call one GameObject Update
- Render one mesh.
- Go to 1.
If it uses the first method then I cannot share the material as I’m changing variables in the shader for each object rendered.
You seem to be asking for contradictory things. Either you have separate materials that have their own texture values, or you have a shared material where all objects have the same texture value. It’s quite impossible to have both at once.
–Eric
Each object material has many common values and the same shader. It seemed wrong to have hundreds of materials when all I want to do is change some shader variables for each mesh being rendered.
If even one value is different, then it requires separate materials, regardless of how many of the other values are the same.
–Eric
Thanks for confirming and answering so quickly Eric, this forum is a very nice place. 