---
title: "withUnsafeBytes(bufferIndex:_:)"
framework: realitykit
role: symbol
role_heading: Instance Method
path: "realitykit/lowlevelmesh/withunsafebytes(bufferindex:_:)"
---

# withUnsafeBytes(bufferIndex:_:)

Reads a Metal vertex buffer synchronously on the CPU.

## Declaration

```swift
@MainActor func withUnsafeBytes(bufferIndex: Int, _ callback: (UnsafeRawBufferPointer) -> Void)
```

## Discussion

Discussion The buffer is only valid for the lifetime of the callback.

## See Also

### Accessing mesh data on the CPU with Swift

- [withUnsafeMutableBytes(bufferIndex:_:)](realitykit/lowlevelmesh/withunsafemutablebytes(bufferindex:_:).md)
- [withUnsafeIndices(_:)](realitykit/lowlevelmesh/withunsafeindices(_:).md)
- [withUnsafeMutableIndices(_:)](realitykit/lowlevelmesh/withunsafemutableindices(_:).md)
- [replaceUnsafeMutableBytes(bufferIndex:_:)](realitykit/lowlevelmesh/replaceunsafemutablebytes(bufferindex:_:).md)
- [replaceUnsafeMutableIndices(_:)](realitykit/lowlevelmesh/replaceunsafemutableindices(_:).md)
