- Home /
Does Static batching on 2D sprites work with random color tone?
Hello, I am not too familiar with static batching in unity. My understanding is, if the gameobjects with 2D sprites are marked as static meaning they dont move, scale or rotate in game unity will use static batching. Given these settings, is static batching used only on gameobjects with same sprites? Also, all these gameobjects have a script attached to them that chooses a random color among list of colors and applies that color to the sprite on their respective Awake functions. Will this break static batching? Please help with any understanding of static batching. Thanks for your responses in advance.
Hello, I answered my own question by testing it out. Changing sprites color at runtime creates an instance of the shared material for the particular sprite and DOES break batching.
It might be possible to get batching for these back if you use a shader that has the color property as a per-renderer property. In that case, it shouldn't be necessary to clone the material for each sprite that uses a different color.
I haven't tested that, though.
Will surely try it out and get back when I get a chance. Thanks for the reply. I briefly read about the pre-renderer properties on Unity Docs and seems like it does what you say and should work. Thanks once again.
Answer by djarcas · Oct 12, 2015 at 02:19 PM
You can use a material property block to alter the colour of the sprites without causing an instance of the material to occur.