Instantiated objects are all white?

Hi all,

So I’m currently wanting my instantiated object to have a random colour when it’s being created, so the code is like:

    if (Input.GetMouseButtonUp (0) && !IsPointerOverUIObject ()) {
    				int r = UnityEngine.Random.Range (0, Center.Count);
    				centerPiece = Instantiate (Center [r], new Vector3 (0, 0, 0), Quaternion.identity) as GameObject;
    				Debug.Log ("R: " + red + " G: " + green + " B: " + blue);
    				centerPiece.GetComponent<MeshRenderer> ().material.color = Color.red;
    }

But currently the object all appear to be white when they are instantiated, or else for some reason locked in a cmyk colour; i.e. when there is a colour being reproduced.

Is this a matter of problem with my code, or how I’ve set up my unity project…? Could any one give me a bit of help?

Your code isn’t complete, so I can only guess:

  1. Does your instantiated object contain only one mesh renderer? Is it located on the root GameObject, or is it further down the hierarchy?
  2. Does the shader you use support colors? Mobile shaders don’t support colors, only textures. Custom shaders may also exclude support for colors.

I should’ve changed that @Arshia001 sorry… i was meant to be new Color (red, green, blue) where I made the random range from 0-255… I’m trying to make it use the Color32 but looks like I’m having problems with a phrase error as my random range is using float but it seems like unity wants a byte value… That’s the only thing I’m trying to get my head around, and reading around the Unity Docs and API. Also thanks for the tip on that Color32 thing @Eno-Khaon