Is there a way to set a sprite's color solid white?

I’m using Sprite Renderer and need to set a sprite color to solid white, to the point where it is only recognizable by its silhouette.

The problem is:

Setting a sprite’s color to white (1.0,1.0,1.0) will result in the sprite having it’s “natural” color.

Funny thing is, if you set it to black, the effect I get is the one I’m aiming for… Except it’s black.

You could argue that it’s a bit hacky, but using a material with a GUI Text Shader is working totally fine for me!

To expand on nyonge’s suggestion, here’s one way to set a SpriteRenderer’s shader to a GUI Text shader at runtime:

using UnityEngine;
using System.Collections;

public class myClass : MonoBehaviour {
	private SpriteRenderer myRenderer;
	private Shader shaderGUItext;
	private Shader shaderSpritesDefault;

	void Start () {
		myRenderer = gameObject.GetComponent<SpriteRenderer>();
		shaderGUItext = Shader.Find("GUI/Text Shader");
		shaderSpritesDefault = Shader.Find("Sprites/Default"); // or whatever sprite shader is being used

	}
}

To set the sprite to white:

void whiteSprite() {
	myRenderer.material.shader = shaderGUItext;
	myRenderer.color = Color.white;
}

And then to set the sprite back to normal:

void normalSprite() {
	myRenderer.material.shader = shaderSpritesDefault;
	myRenderer.color = Color.white;
}

You could add a mask to the sprite renderer/Image
and then create a child that’s empty and white, so you just got the white silhouette.

Greetings,

Max

You would have to write a new shader to replace the color of every pixel with white.

Then you could replace the default material on the SpriteRenderer.material with a duplicate that has the new shader.

You would have to work around the SpriteRenderer and be careful not to change the default sprite shader and make all your sprites white.

So I just wanted to expand on ericdl’s great solution. I built on that and made a class to turn an entire collection of sprites white and back. Useful for things like character rigs that are made of multiple sprites:

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

public class WhiteSpriteSetter : MonoBehaviour
{
    SpriteRenderer[] allSprites;
    Shader[] defaultShaders;
    Color[] defaultColors;
    Shader textGUIShader;

    void Start()
    {
        textGUIShader = Shader.Find("GUI/Text Shader");

        allSprites = gameObject.GetComponentsInChildren<SpriteRenderer>();
        defaultShaders = new Shader[allSprites.Length];
        defaultColors = new Color[allSprites.Length];
        for(int i = 0; i < allSprites.Length; i++)
        {
            defaultShaders[i] = allSprites[i]?.material?.shader;
            defaultColors[i] = allSprites[i].color;
        }
    }

    public void TurnWhite()
    {
        for (int i = 0; i < allSprites.Length; i++)
        {
            allSprites[i].material.shader = textGUIShader;
            allSprites[i].color = Color.white;
        }
    }

    public void TurnNormal()
    {
        for (int i = 0; i < allSprites.Length; i++)
        {
            allSprites[i].material.shader = defaultShaders[i];
            allSprites[i].color = defaultColors[i];
        }
    }
}