<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/TextureResource/texture2DArray(slices:named:options:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation15TextureResourceC14texture2DArray6slices5named7optionsACSaySo10CGImageRefaG_SSSgAC13CreateOptionsVtYaKFZ::OverloadGroup"
  },
  "title" : "texture2DArray(slices:named:options:)"
}
-->

# texture2DArray(slices:named:options:)

Asynchronously creates a 2D texture array by generating it from images.

```
@MainActor @preconcurrency static func texture2DArray(slices: [CGImage], named resourceName: String? = nil, options: TextureResource.CreateOptions) async throws -> TextureResource
```

## Parameters

`slices`

The source images, one per 2D array index. All images need to have the same size and format.

`resourceName`

A unique name for syncing the texture resource across the network.
The name is empty if you don’t include one.

`options`

A configuration for generating the texture.

## Discussion

RealityKit creates a <doc://com.apple.documentation/documentation/Metal/MTLTextureType/type2DArray>
texture with `arrayLength == slices.count` from an array of images.

You can assign the resulting texture to a material you create in Reality Composer Pro that requires a 2D texture array.

```swift
// Create a 2D array texture from image slices.
let texture2DArray = try TextureResource.texture2DArray(
    slices: [image0, image1, image2],
    options: TextureResource.CreateOptions(semantic: .color))

Task {
    // Assign the 2D array texture to a compatible shader graph material parameter.
    var material = try await ShaderGraphMaterial(
        named: "/Root/Spaceship/MaterialWith2DArray", from: url)

    try material.setParameter(
        name: "input2DArray", value: .textureResource(texture2DArray))
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)