Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2025 Graphics & GamesSpatial Computing

WWDC25 · 18 min · Graphics & Games / Spatial Computing

Explore spatial accessory input on visionOS

Learn how you can integrate spatial accessories into your app. Display virtual content, interact with your app, track them in space, and get information on interactions for enhanced virtual experiences on visionOS.

Watch at developer.apple.com ↗

Transcript all transcripts

Chapters

Code shown on screen · 5 snippets

Get in-app transforms swift · at 0:09 ↗
// Get in-app transforms

let session = SpatialTrackingSession()

let configuration = SpatialTrackingSession.Configuration(tracking: [.accessory])

await session.run(configuration)
Check for accessory support swift · at 4:57 ↗
// Check spatial accessory support

NotificationCenter.default.addObserver(forName: NSNotification.Name.GCControllerDidConnect, object: nil, queue: nil) {
  notification in
    if let controller = notification.object as? GCController,
       controller.productCategory == GCProductCategorySpatialController {
             
    }
}
Anchor virtual content to an accessory swift · at 7:20 ↗
// Anchor virtual content to an accessory

func setupSpatialAccessory(device: GCDevice) async throws {

    let source = try await AnchoringComponent.AccessoryAnchoringSource(device: device)

    guard let location = source.locationName(named: "aim") else {
        return
    }
  
    let sculptingEntity = AnchorEntity(.accessory(from: source, location: location),
                                       trackingMode: .predicted)

}
Add haptics to an accessory swift · at 9:45 ↗
// Add haptics to an accessory

let stylus: GCStylus = ...

guard let haptics = stylus.haptics else {
    return
}

guard let hapticsEngine: CHHapticEngine = haptics.createEngine(withLocality: .default) else {
    return
}

try? hapticsEngine.start()
Access ARKit anchors from AnchorEntity swift · at 11:25 ↗
// Access ARKit anchors from AnchorEntity

func getAccessoryAnchor(entity: AnchorEntity) -> AccessoryAnchor? {
    if let component = entity.components[ARKitAnchorComponent.self],
       let accessoryAnchor = component.anchor as? AccessoryAnchor {
        return accessoryAnchor
    }
    return nil
}

Resources