<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/ARView/RenderCallbacks-swift.struct/prepareWithDevice",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:10RealityKit6ARViewC15RenderCallbacksV17prepareWithDeviceySo9MTLDevice_pcSgvp"
  },
  "title" : "prepareWithDevice"
}
-->

# prepareWithDevice

A callback function for doing initial setup work.

```
var prepareWithDevice: ((any MTLDevice) -> Void)?
```

## Discussion

If you assign a function to
[`prepareWithDevice`](/documentation/RealityKit/ARView/RenderCallbacks-swift.struct/prepareWithDevice),
RealityKit calls that function once, after it does its setup work,
but before it renders the next frame. If you register a
[`prepareWithDevice`](/documentation/RealityKit/ARView/RenderCallbacks-swift.struct/prepareWithDevice) callback
during app startup, RealityKit calls it before it renders the first
frame. A callback function looks like this:

```swift
    func myPostProcessSetupCallback(device: MTLDevice) {
        // Handle setup work here.
    }
```

To register the function so RealityKit calls it, assign it to the
[`prepareWithDevice`](/documentation/RealityKit/ARView/RenderCallbacks-swift.struct/prepareWithDevice) property
of the view’s [`renderCallbacks`](/documentation/RealityKit/ARView/renderCallbacks-swift.property) property.

```swift
arView.renderCallbacks.prepareWithDevice = myPostProcessSetupCallback
```

To remove the callback, assign `nil`.

```swift
arView.renderCallbacks.prepareWithDevice = nil
```

If you assign a new closure or function to the property after
setting it to `nil`, RealityKit calls the new closure before it
renders the next frame. In that case, avoid doing long-running tasks
in the callback function to avoid rendering hitches.

---

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)