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 ↗Chapters
Code shown on screen · 5 snippets
Get in-app transforms
// Get in-app transforms
let session = SpatialTrackingSession()
let configuration = SpatialTrackingSession.Configuration(tracking: [.accessory])
await session.run(configuration) Check for accessory support
// 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
// 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
// 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
// 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
Related sessions
-
15 min -
25 min -
32 min -
15 min -
26 min