Is there a faster way of changing the color or lots of materials every frame?

Using material.color = newColor;

But this is over a large 3d grid of cubes and it’s extremely slow.

Is there a faster way of changing dynamic color over a large set of meshes?

Check out MaterialPropertyBlocks

1 Like

That creates a new material instance for each cube, which is rather wasteful and slow. See:

https://docs.unity3d.com/ScriptReference/Renderer-material.html

Use MaterialPropertyBlocks as georgerh suggested. This article may be helpful:
https://thomasmountainborn.com/2016/05/25/materialpropertyblocks/

are you sure this is correct? I know that someMeshRenderer.material.whatever creates a new material (as is mentioned in the docs you linked). but just calling someMaterial.color does not create a new material from what i know. i see that all my objects with a material reflect the color change i make to a material via myMaterial.color = newColor.

It’s calling the renderer’s material property getter that creates a new instance: that is, accessing renderer.material. If your “material” is a variable referencing a material, them no, it won’t create a new material.

OP said he was doing “material.color = something” over a large grid of cubes to give each one a different color and it was slow. So I’m 100% sure that he was doing “cube.renderer.material.color = something” for each cube, and why I mentioned this.

1 Like