swiftyboi
swiftyboi

Reputation: 3221

visionOS - Can you use a RealityView outside of an ImmersiveSpace?

I have a visionOS app that supports both a WindowGroup and an ImmersiveSpace.

import SwiftUI

@main
struct VisionApp: App {
    
    @State var immersionStyle: ImmersionStyle = .mixed
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        
        ImmersiveSpace(id: "MySpace") {
            MySpace()
        }
        .immersionStyle(selection: $immersionStyle, in: .mixed)
        
    }
}

The window is a normal window. I am able to load up my SwiftUI views and also use other apps like Safari. I have a button to launch the ImmersiveSpace.

The ImmersiveSpace is not fully immersive. There are a few models and particle emitters, but otherwise you can still see all of your actual surroundings. I can still see my app's window, but unfortunately it appears that when you launch an ImmersiveSpace it causes all other apps to be backgrounded.

I've tried putting RealityView inside a WindowGroup, but it does not seem to work:

WindowGroup {
    RealityView {
        /// ...
        /// ...
}

I suspect this is intended behavior and a limitation of ImmersiveSpace, but I am asking to be sure.

Upvotes: 0

Views: 498

Answers (1)

Ben Gottlieb
Ben Gottlieb

Reputation: 85532

You can use a RealityView in both a regular window and a volume. I just tried placing a RealityView in each of these, and it works fine. Maybe post more of your code?

Upvotes: 1

Related Questions