Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Texture2DArray

Class for handling 2D texture arrays.
Read time 8 minutesLast updated 3 days ago

Definition

  • Type: Class
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
  • Inherits from: Texture
public sealed class Texture2DArray : Texture

Remarks

Modern graphics APIs (e.g. D3D10 and later, OpenGL ES 3.0 and later, Metal etc.) support "texture arrays", which is an array of same size & format textures. From the shader side, they are treated as a single resource, and sampling them needs an extra coordinate that indicates which array element to sample from.
Typically texture arrays are useful as an alternative for texture atlases, or in other cases where objects use a set of same-sized textures (e.g. terrains).
Currently in Unity texture arrays do not have an import pipeline for them, and must be created from code, either at runtime or in editor scripts. Using Graphics.CopyTexture is useful for fast copying of pixel data from regular 2D textures into elements of a texture array. From editor scripts, a common way of creating serialized texture array is to create it, fill with data (either via Graphics.CopyTexture from regular 2D textures, or via Texture2DArray.SetPixels or Texture2DArray.SetPixels32) and save it as an asset via AssetDatabase.CreateAsset.
Note that not all platforms and GPUs support texture arrays; for example Direct3D9 does not. Use SystemInfo.supports2DArrayTextures to check. Also, this class does not support Texture2DArray creation with a Crunch compression TextureFormat.

Constructors

Properties

Property

Description

activeMipmapLimitThe number of high resolution mipmap levels from the texture that Unity doesn't upload to the GPU. (Read Only)
depthNumber of elements in a texture array (Read Only).
formatTexture format (Read Only).
ignoreMipmapLimitThis property causes a texture to ignore all texture mipmap limit settings.
mipmapLimitGroupThe name of the texture mipmap limit group that this texture is associated with. (Read Only)

Static Properties

Property

Description

allSlicesRead Only. This property is used as a parameter in some overloads of the CommandBuffer.Blit, Graphics.Blit, CommandBuffer.SetRenderTarget, and Graphics.SetRenderTarget methods to indicate that all texture array slices are bound. The value of this property is -1.

Methods

Method

Description

ApplyCopies changes you've made in a CPU texture to the GPU.
CopyPixelsCopies pixel data from another texture on the CPU.
GetPixelDataGets the raw data from a texture.
GetPixelsGets the pixel color data for a mipmap level of a slice as Color structs.
GetPixels32Gets the pixel color data for a mipmap level of a slice as Color32 structs.
SetPixelDataSets the raw data of an entire mipmap level directly in CPU memory.
SetPixelsSets the pixel colors of an entire mipmap level of a slice.
SetPixels32Sets the pixel colors of an entire mipmap level of a slice.

Inheritance

Inherited Members

Operators

Operator

Description

operator ==Compares two object references to see if they refer to the same object.
boolDetermines whether the object exists.
operator !=Compares if two objects refer to a different object.