# SetPixels

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

## Definition

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

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

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

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

### Parameters

**** (\[Color\[]]\(/engine/6000.3/script-reference/unityengine/color)): The array of pixel colours to use. This is a 2D image flattened to a 1D array.**** (\[CubemapFace]\(/engine/6000.3/script-reference/unityengine/cubemapface)): The [CubemapFace](/engine/6000.3/script-reference/unityengine/cubemapface.md) to write `colors` 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.3/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.3/script-reference/unityengine/texture/isreadable.md) must be `true`, and you must call [Cubemap.Apply](/engine/6000.3/script-reference/unityengine/cubemap/apply.md) after `SetPixels` to upload the changed pixels to the GPU.

[Cubemap.Apply](/engine/6000.3/script-reference/unityengine/cubemap/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 face texture. The size of the array must be the width × height of the mipmap level.

A single call to `SetPixels` is usually faster than multiple calls to [Cubemap.SetPixel](/engine/6000.3/script-reference/unityengine/cubemap/setpixel.md), especially for large textures.

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

You can use `SetPixels` with the following [texture formats](/engine/6000.3/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: [Cubemap.GetPixels](/engine/6000.3/script-reference/unityengine/cubemap/getpixels.md), [Cubemap.SetPixelData](/engine/6000.3/script-reference/unityengine/cubemap/setpixeldata.md), [Cubemap.Apply](/engine/6000.3/script-reference/unityengine/cubemap/apply.md), [mipmapCount](/engine/6000.3/script-reference/unityengine/texture/mipmapcount.md).

### Examples

```csharp
// copy a texture to the +X face of a cubemap

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Cubemap c;
    public Texture2D t;
    private Color[] CubeMapColors;

    void Example()
    {
        CubeMapColors = t.GetPixels();
        c.SetPixels(CubeMapColors, CubemapFace.PositiveX);
        c.Apply();
    }
}
```

## SetPixels(Color\[], CubemapFace)

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

```csharp
public void SetPixels(Color[] colors, CubemapFace face)
```

### Parameters

**** (\[Color\[]]\(/engine/6000.3/script-reference/unityengine/color)): The array of pixel colours to use. This is a 2D image flattened to a 1D array.**** (\[CubemapFace]\(/engine/6000.3/script-reference/unityengine/cubemapface)): The [CubemapFace](/engine/6000.3/script-reference/unityengine/cubemapface.md) to write `colors` to.

### Remarks

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

[Cubemap.Apply](/engine/6000.3/script-reference/unityengine/cubemap/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 face texture. The size of the array must be the width × height of the mipmap level.

A single call to `SetPixels` is usually faster than multiple calls to [Cubemap.SetPixel](/engine/6000.3/script-reference/unityengine/cubemap/setpixel.md), especially for large textures.

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

You can use `SetPixels` with the following [texture formats](/engine/6000.3/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: [Cubemap.GetPixels](/engine/6000.3/script-reference/unityengine/cubemap/getpixels.md), [Cubemap.SetPixelData](/engine/6000.3/script-reference/unityengine/cubemap/setpixeldata.md), [Cubemap.Apply](/engine/6000.3/script-reference/unityengine/cubemap/apply.md), [mipmapCount](/engine/6000.3/script-reference/unityengine/texture/mipmapcount.md).

### Examples

```csharp
// copy a texture to the +X face of a cubemap

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Cubemap c;
    public Texture2D t;
    private Color[] CubeMapColors;

    void Example()
    {
        CubeMapColors = t.GetPixels();
        c.SetPixels(CubeMapColors, CubemapFace.PositiveX);
        c.Apply();
    }
}
```
