In Unity's editor I have set a swatch with some colours that are used throughout our game:

The colour picker, with an added swatch of colours

This swatch is saved in a file in the project's Assets folder:

\ProjectFolder\Assets\Editor\Main Colors.colors

I would like to use the colours in this swatch somewhere in a script:

GetComponent<Graphic>().color = SomethingHere.MainRed;

What is the best way to do this? Or is it not possible?


I also think that I'm doing something really strange? I couldn't find any answer to this question online. But having the same colour library in the scripts as I use in the editor would be really nice.


1 Answer 1


Better solution would be just to create ScriptableObject, with List<Entry>:

class Colors: ScriptableObject 
    public class Entry 
         public string name;
         public Color color;

    public List<Entry> colors = new List<Entry>();

    public Color GetColor(string name) 
         var entry = colors.Find(c => c.name == name);
         if (entry != null) {
              return entry.color;
         return Color.white;

and later set that scriptable object anywhere you want.

Colors colors_db;
var color = colors_db.GetColor("MainRed")

Color preset you've saved is basically the same, but it's Editor only object.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .