[SOLVED] How to Construct a New Color Via Code?

So I know the scripting reference has it listed out pretty simple, but it’s not working for me. I have the code:
yellowGoldfishColor = Color (255, 255, 255, 255);
But it assigns the color with rgba value of 255, 255, 0, 255 instead and gives 2 errors:

“Invalid normalized color: RGBA(150.000, 255.000, 0.000, 255.000), normalize value: 0
UnityEditor.DockArea:OnGUI()”
And
“Setting normalized color with a non-normalized color: RGBA(150.000, 255.000, 0.000, 255.000)
UnityEditor.DockArea:OnGUI()”

I don’t know what I’ve done wrong, am starting to wonder if the reference is wrong for 5.6?

Using Unity 5.6.0f3

Any help would be greatly appreciated!

EDIT: Result is always (150, 255, 0, 255) no matter what values I have in the code. Have also tried Color32 and that got rid of the errors, but problem still persisted.

– Chris

You’re trying to feed it integers when it expects floats.

Color yellowGoldfishColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);

is another option. :slight_smile:

I tried that first and it didn’t work. Produced same results as with integers.

Well with that I get no errors, but the (255, 255, 255, 255) that I have translate to (150, 255, 0, 255).

EDIT: In fact, the result is always (150, 255, 0, 255) no matter what values I put in the code.

1 Like

Well, both should work so something is funky :wink: (and not give you a different value while doing so**) lol

We’re going to need to see the script it’s being used in then. Both Color and Color32 with integers and with floats are working for me in Unity 5.6.0f3. Here is the code I’m using to test it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Foo : MonoBehaviour {
   
    private Color32 yellowGoldfishColor;

    // Use this for initialization
    void Start () {
        yellowGoldfishColor = new Color(255, 255, 255, 255);
    }
   
    // Update is called once per frame
    void Update () {
        Debug.Log(yellowGoldfishColor);
    }
}

Solved the problem. Problem wasn’t the colors at all. It was the reason why you shouldn’t code when you’re tired (did wrong check in if statement). :stuck_out_tongue:

Thanks for the help all. :slight_smile:

1 Like

Awesome. I always like seeing [solved] in threads :wink: