<!--
{
  "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/Contents/Slice/slice(unsafeBuffer:offset:size:bytesPerRow:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation15TextureResourceC8ContentsV5SliceV5slice12unsafeBuffer6offset4size11bytesPerRowAGSo9MTLBuffer_p_S3itFZ"
  },
  "title" : "slice(unsafeBuffer:offset:size:bytesPerRow:)"
}
-->

# slice(unsafeBuffer:offset:size:bytesPerRow:)

Specifies a single mipmap level slice of a texture resource with pixel data that RealityKit copies from a Metal buffer.

```
static func slice(unsafeBuffer buffer: any MTLBuffer, offset: Int = 0, size: Int, bytesPerRow: Int) -> TextureResource.Contents.Slice
```

## Parameters

`buffer`

The source buffer.
Don’t modify this buffer while using it as the source of a copy operation.

`offset`

The byte position in the source buffer where the copying starts.
The offset needs to be a multiple of the destination texture’s pixel size, in bytes.

`size`

The number of bytes in the source buffer (starting from `offset`) available for copying.

`bytesPerRow`

The stride in bytes between rows of texture data that RealityKit stores in the source buffer.
The value needs to be a multiple of the destination texture’s pixel size, in bytes.

## Discussion> Important: A ``doc://com.apple.RealityKit/documentation/RealityKit/TextureResource/Contents/Slice`` that you create with this function and use to create a ``doc://com.apple.RealityKit/documentation/RealityKit/TextureResource``
> copies from the source buffer. That copy occurs when initializing the texture resource. The caller
> is responsible for ensuring that the system doesn’t modify the source Metal buffer while copying it to a texture.

---

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)