Applying a palette to a Unity scene

This part of the tutorial is Unity-specific, and is mostly not applicable to other platforms.

Applying color to an object

When you have a palette of colors, you'll want to apply the colors to parts of your scene. Applying a color to a mesh using SetColor can be done fairly straightforward:

//get the renderer component, apply any color to the material
rend = someObject.GetComponent<Renderer>();

Instead of setting the color to, you can use one of the colors from the palette you generated. This could be colorPalette[i] in a for-loop, or when using a different color space (for example with the ColorHSL struct, provided in the Unitypackage) it is important to get the rgb values to input into the material.

Sorting colors using the Unity hierarchy window

Using propertyblocks

Instead of getting the renderer and setting the color of the material, you could also use a propertyblock. This requires a slight change to your shader:

[PerRendererData]_Color ("Color", Color) = (1,1,1,1) //the [PerRenderData] will allow for the use of propertyblocks

and a slight change to the code as well:

//apply the color to the propertyblock, then apply the propertyblock to the renderer
MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
rend = someObject.GetComponent<Renderer>();

When applying color to a lot of objects at once, this will stop material instancing and lower calculation time. This tutorial gives a more in-depth explaination of this.

Image of color palette applied to a simple scene

Determining which object gets which color

Determining which color is applied to which object can be important for having a coherent result. There's two main things to consider here: how you want the result to look, and how you want to structure your Unity scene.
A method I like to use is sort all gameObjects that will share color into the same parent object, and reference the parent objects to the script that applies the color.

for (int i = 0; i < 6; i++) {
foreach (Transform child in paletteGroups[i]) {
Renderer rend = child.GetComponent<Renderer>();
rend.material.SetColor("_Color", colorPalette[i].rgb);

This requires little code and allows for intuitively moving gameobjects between the colors, but it also has a couple of drawbacks. For example, the scene becomes cluttered and parts that would usually be together, may have to be put in completely different parents to get the right colors. The objects are also somewhat tied to the specific spot in the palette that they were grouped into, as moving it to another parent makes the scene get even more incomprehensible quickly.

Another way of determining the color per object, is to have a script attached to all (groups of) objects, that manage which color of the palette is applied to the object(s). This allows for more flexibility and a more orderly scene, but requires scripts attached to way more gameObjects.
The manager script can have a much more simplified code:

foreach (ObjectBasedColor obj in paletteObjects) { obj.SetColor(colorPalette); }

And the object (group) that it calls upon handles the rest:

public void SetColor(ColorHSL[] colorPalette) {
foreach (Renderer rend in rendererList) {
rend.material.SetColor("_Color", colorPalette[colorID % colorPalette.Length].rgb);

Changing other colors

Some things other than gameobjects can have their color changed by script, including (but not limited to) fog and skyboxes. These are very useful for generating color palettes for environments, as they have big impact on the mood of a resulting image.
Changing fog through code requires only one line:

RenderSettings.fogColor =;

And the skybox is relatively simple as well, as you can change the properties of its material like you can with gameObjects, as long as you reference it in the inspector:


To get the most out of this, you might need a custom skybox. There is one in the Unitypackage that has two color inputs and shows a gradient between the two, but anything else can work too.

A little scene with matching fog and skybox settings