I am attempting to run the sample code from this tutorial in a VisionOS simulator but whenever I try to open the immersive space, the app crashes with this error:

Unable to present an Immersive Space for id 'CubeMeshInteraction': Error Domain=FBSWorkspaceErrorDomain Code=1 "scene invalidated before create completion"

I haven't edited the code at all since downloading. What could be the issue?

1

There are 1 best solutions below

0
Andy Jazz On

Since SceneReconstructionExample visionOS app uses ARKit's Hand Tracking Provider and Scene Reconstruction Provider, you will not be able to run it on Xcode Simulator. This app requires a real Vision Pro device to work. To check if providers are supported or not, use this code:

import SwiftUI
import RealityKit
import ARKit

@main struct YourApp : App {
    @StateObject var setup = Setup()

    var body: some SwiftUI.Scene {
        ImmersiveSpace {
            RealityView { content in
                let sphere = ModelEntity(mesh: .generateSphere(radius: 0.2))
                sphere.position = [0.0, 1.5,-2.0]
                content.add(sphere)
            }
            .task {
                await setup.runSession()
            }
        }
        .immersionStyle(selection: .constant(.full), in: .full)
    }
}

@MainActor class Setup : ObservableObject {
    let session = ARKitSession()

    let worldTracking = WorldTrackingProvider()
    let planeDetection = PlaneDetectionProvider(alignments: [.horizontal])
    let scnReconstruct = SceneReconstructionProvider(modes: [.classification])
    let handTracking = HandTrackingProvider()

    func runSession() async {
        Task {                
            print("Is World Tracking supported here? –> 
                       \(WorldTrackingProvider.isSupported)")
            print("Is Plane Detection supported here? –>  
                       \(PlaneDetectionProvider.isSupported)")
            print("Is Scene Reconstruction supported here? –>  
                       \(SceneReconstructionProvider.isSupported)")
            print("Is Hand Tracking supported here? –> 
                       \(HandTrackingProvider.isSupported)")
            
            try? await session.run([
                                      worldTracking,
                                      // handTracking,
                                      // planeDetection,
                                      // scnReconstruct
                                   ])
        }
    }
}

//  Result:

//  Is World Tracking supported here? –> true
//  Is Plane Detection supported here? –>  false
//  Is Scene Reconstruction supported here? –>  false
//  Is Hand Tracking supported here? –> false