material instead of sharedmaterial


i making a space shoot em up and i need about 20-30 sprites in the background showing some clouds.

i want to change color of clouds for each sprite with a special color.
is it a problem to use a script that create a instance of the material in the editor even if unity say “materail will leak, use shared material instead”
because i found boring to duplicate material in assets just to change color and have 100 materials different just by its color.

actually, i use a script that change the color just a the start of the game, just for the sprite but it is not visual in the editor and it’s difficult to change color.

so it is really a problem using material in editor for 50 objects?

i talk about cloud but also some flares (for suns,stars in my game)

it’s sure, if i think i will use a material more than once, i will use a material in asset.

thank for answer

If you edit the color on the material it will make a copy of the material, which will prevent batching.

I believe you can edit the color property in the mesh if you are using a shader that supports it.

To make a script run in the editor you can use ExecuteInEditMode

ok , you can fo this by changing the renderer color as in Unity - Scripting API: Material.color

or you can simply create a material in the memory and attach shader & textures right from a javaScript