Skip to content

Random Seed

Video about it:

There are some effects with a random component (such as flicker, hologram, glitch…). By default if you have 2 instances of a material that uses these effects they will look the same and it may look bad in your game. To avoid repetition you can add the RandomSeed component to the Object that contains the Renderer (Sprite, Tilemap, Sprite Shape, Particle System, Mesh) or UI Image you want to affect. It applies its seed when the object starts, so the difference shows in Play mode.

Four copies of the demo's waving flag sharing one material. Without RandomSeed they wave in step like one flag repeated; with a RandomSeed on each they wave out of step

On a UI Image the seed is written to the Image’s material, and UI materials are shared, so give each Image its own material instance or they all end up with the same seed.

The Random Seed component added in the Inspector, which has no settings beyond its script

Doing this won’t break batching as long as Gpu Instancing is enabled in the Advanced Configuration Options of the Material Inspector and the Main Texture is set directly in the Material asset. This means that you’ll need one instance of a material that is supposed to batch for each different texture you want to use.

The Advanced Configuration of the Material Inspector, with Enable GPU Instancing near the bottom
The Test Instancing material's General Properties, with an arrow pointing at the soldier texture set directly in its Main Texture slot