# SetPixels

> Sets the pixel colors of an entire mipmap level of a slice.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.6/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

## SetPixels(Color\[], int, int)

Sets the pixel colors of an entire mipmap level of a slice.

```csharp
public void SetPixels(Color[] colors, int arrayElement, int miplevel)
```

### Parameters

**** (\[Color\[]]\(/engine/6000.6/script-reference/unityengine/color)): The array of pixel colours to use. This is a 2D image flattened to a 1D array.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The array slice to write to.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The mipmap level to write `colors` to. The range is `0` through the texture's [Texture.mipmapCount](/engine/6000.6/script-reference/unityengine/texture/mipmapcount.md). The default value is `0`.

### Remarks

This method sets pixel data for the texture in CPU memory. [Texture.isReadable](/engine/6000.6/script-reference/unityengine/texture/isreadable.md) must be `true`, and you must call [Texture2DArray.Apply](/engine/6000.6/script-reference/unityengine/texture2darray/apply.md) after `SetPixels` to upload the changed pixels to the GPU.

[Texture2DArray.Apply](/engine/6000.6/script-reference/unityengine/texture2darray/apply.md) is an expensive operation because it copies all the pixels in the texture even if you've only changed some of the pixels, so change as many pixels as possible before you call it.

`colors` must contain the pixels row by row, starting at the bottom left of the texture. The size of the array must be the width × height of the mipmap level.

`SetPixels` might be slower than some other texture methods because it converts the [Color](/engine/6000.6/script-reference/unityengine/color.md) struct into the format the texture uses. To set pixel data more quickly, use [Texture2DArray.SetPixelData](/engine/6000.6/script-reference/unityengine/texture2darray/setpixeldata.md) instead.

You can use `SetPixels` with the following [texture formats](/engine/6000.6/script-reference/unityengine/textureformat.md):

* Alpha8
* ARGB32
* ARGB4444
* BGRA32
* R16
* R16\_SIGNED
* R8
* R8\_SIGNED
* RFloat
* RG16
* RG16\_SIGNED
* RG32
* RG32\_SIGNED
* RGB24
* RGB24\_SIGNED
* RGB48
* RGB48\_SIGNED
* RGB565
* RGB9e5Float
* RGBA32
* RGBA32\_SIGNED
* RGBA4444
* RGBA64
* RGBA64\_SIGNED
* RGBAFloat
* RGBAHalf
* RGFloat
* RGHalf
* RHalf

For all other formats, `SetPixels` fails. Unity throws an exception when `SetPixels` fails.

Additional Resources: [Texture2DArray.GetPixels](/engine/6000.6/script-reference/unityengine/texture2darray/getpixels.md), [Texture2DArray.SetPixels32](/engine/6000.6/script-reference/unityengine/texture2darray/setpixels32.md), [Texture2DArray.SetPixelData](/engine/6000.6/script-reference/unityengine/texture2darray/setpixeldata.md), [Texture2DArray.Apply](/engine/6000.6/script-reference/unityengine/texture2darray/apply.md), [mipmapCount](/engine/6000.6/script-reference/unityengine/texture/mipmapcount.md).

## SetPixels(Color\[], int)

Sets the pixel colors of an entire mipmap level of a slice.

```csharp
public void SetPixels(Color[] colors, int arrayElement)
```

### Parameters

**** (\[Color\[]]\(/engine/6000.6/script-reference/unityengine/color)): The array of pixel colours to use. This is a 2D image flattened to a 1D array.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The array slice to write to.

### Remarks

This method sets pixel data for the texture in CPU memory. [Texture.isReadable](/engine/6000.6/script-reference/unityengine/texture/isreadable.md) must be `true`, and you must call [Texture2DArray.Apply](/engine/6000.6/script-reference/unityengine/texture2darray/apply.md) after `SetPixels` to upload the changed pixels to the GPU.

[Texture2DArray.Apply](/engine/6000.6/script-reference/unityengine/texture2darray/apply.md) is an expensive operation because it copies all the pixels in the texture even if you've only changed some of the pixels, so change as many pixels as possible before you call it.

`colors` must contain the pixels row by row, starting at the bottom left of the texture. The size of the array must be the width × height of the mipmap level.

`SetPixels` might be slower than some other texture methods because it converts the [Color](/engine/6000.6/script-reference/unityengine/color.md) struct into the format the texture uses. To set pixel data more quickly, use [Texture2DArray.SetPixelData](/engine/6000.6/script-reference/unityengine/texture2darray/setpixeldata.md) instead.

You can use `SetPixels` with the following [texture formats](/engine/6000.6/script-reference/unityengine/textureformat.md):

* Alpha8
* ARGB32
* ARGB4444
* BGRA32
* R16
* R16\_SIGNED
* R8
* R8\_SIGNED
* RFloat
* RG16
* RG16\_SIGNED
* RG32
* RG32\_SIGNED
* RGB24
* RGB24\_SIGNED
* RGB48
* RGB48\_SIGNED
* RGB565
* RGB9e5Float
* RGBA32
* RGBA32\_SIGNED
* RGBA4444
* RGBA64
* RGBA64\_SIGNED
* RGBAFloat
* RGBAHalf
* RGFloat
* RGHalf
* RHalf

For all other formats, `SetPixels` fails. Unity throws an exception when `SetPixels` fails.

Additional Resources: [Texture2DArray.GetPixels](/engine/6000.6/script-reference/unityengine/texture2darray/getpixels.md), [Texture2DArray.SetPixels32](/engine/6000.6/script-reference/unityengine/texture2darray/setpixels32.md), [Texture2DArray.SetPixelData](/engine/6000.6/script-reference/unityengine/texture2darray/setpixeldata.md), [Texture2DArray.Apply](/engine/6000.6/script-reference/unityengine/texture2darray/apply.md), [mipmapCount](/engine/6000.6/script-reference/unityengine/texture/mipmapcount.md).
