Unity is using two distinct representations for a RGBA Color:
- Color: Each color component is a floating point value with a range from 0 to 1. (this format is used inside all graphics cards and shaders).
- Color32: Each color component is a byte value with a range from 0 to 255. (32bit RGBA).
Color32 is much faster and uses 4X less memory. Color and Color32 can be implicitly converted to each other.
Compared to SetPixels, SetPixels32 is much faster and uses less memory.
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
void Start()
{
Renderer rend = GetComponent<Renderer>();
Texture2D texture = Instantiate(rend.material.mainTexture) as Texture2D;
rend.material.mainTexture = texture;
// ...
Color[] colors = new Color[3];
colors[0] = Color.red;
colors[1] = Color.green;
colors[2] = Color.blue;
texture.SetPixels(colors);
// ...
}
}If 32bit-RGBA is compatible with your scenario, use SetPixels32 instead.
Note: sometimes though 32bit-RGBA is not enough (like for HDR, Dolby Vision or advanced color manipulation).
No automatic code fix is available for this diagnostic.