- Home /
Is it possible to change the colour of game objects without increasing the number of draw calls?
As an experiment, I have a simple game object instantiated a few hundred times, and I'm trying to set the colour of each instance separately in code.
I understand that when I modify the material on an instance (i.e. renderer.material.color), the number of draw calls increases, since it effectively becomes a new material (is that right?). Interestingly this happens even when renderer.material is accessed, not modified.
Out of curiosity, is there a way to set the colour of an object without increasing the number of draw calls? Only thing I can think of is using particles instead of individual game objects, but I'm wondering if it's the only option. The plan is to animate them so I can't use the CombineChildren script..
Answer by Kryptos · Nov 13, 2012 at 09:22 AM
Yes. There is a way. You can set the vertex colors. Your texture should be a white texture and the shader used for your material should read/use the vertex colors (most particle shaders do).
This way you can choose a different color for each object while keeping the same material, thus preventing additional draw calls.
i thought that was only for the particle shader?
what's another shader that can be used here?
That seemed to do the trick! I've only just started to play with shaders, so writing my own to test this further should be a fun task - think I'll start here:
http://answers.unity3d.com/questions/189584/how-to-get-vertex-color-in-a-cg-shader.html
Thanks both of you for your help!
Your answer
![](https://koobas.hobune.stream/wayback/20220613083804im_/https://answers.unity.com/themes/thub/images/avi.jpg)