visionOS Immersive Space is dismissed when app goes in the background

Hi,

My app launches with a mixed immersive space. the Preferred Default Scene Session Role is set to Immersive Space Application Session Role.

 ImmersiveSpace(id: "sceneSpace"){
            ImmersiveView()
                .environmentObject(modelObject)
        }.immersionStyle(selection: .constant(.mixed), in: .mixed)

Other WindowGroups are opened too. Problem: When the x button (bottom left corner) is tapped on any WindowGroup the immersive space is dismissed. When the user opens the app again the immersive space is gone.

The same happens when the user opens the Home Screen.

How can I keep the same immersive space when the app is opened again.

Thank you!

that x button is the close window means that will close the whole app in my opinion

thanks Zippy Games

Hello @gebs,

The behavior you described is unexpected and I was not able to reproduce it in a focused project, is it possible that you are calling the dismissImmersiveSpace action in your code when the window closes?

@gebs

Ok thanks for confirming, can you try reproducing with this code?



import SwiftUI
import RealityKit

@main
struct fooApp: App {
    
    @Environment(\.openWindow) private var openWindow
    
    var body: some SwiftUI.Scene {
        
        ImmersiveSpace {
            RealityView { content in
                let box = ModelEntity(mesh: .generateBox(size: 0.1), materials: [SimpleMaterial(color: .red, isMetallic: false)])
                box.position = [0, 1.2, -1]
                
                content.add(box)
            }
            .task {
                openWindow(id: "My Window")
            }
        }
        
        WindowGroup(id: "My Window") {
            Text("Hello World.")
        }
    }
}

@gebs, Ok, there were two issues you mentioned:

  1. "Problem: When the x button (bottom left corner) is tapped on any WindowGroup the immersive space is dismissed."
  2. "When the user opens the app again the immersive space is gone. The same happens when the user opens the Home Screen."

Can you confirm that the first issue is not happening with the code I provided? Then I can look into the expected behavior for the second problem.

visionOS Immersive Space is dismissed when app goes in the background
 
 
Q