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!

Replies

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

thanks Zippy Games

  • when the x button is tapped the VisionOS will keep at least one windowGroup even if you dismiss all the windows.

Add a Comment

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?

  • Hi @gchiste thank you for your reply. I am not, the immersive space has a realityview with 3d models in its content. When the user taps on the home button the realityview is dismissed.

Add a Comment

@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.")
        }
    }
}
  • @gchiste With your code, if I tap on the home button the realityview disappears and the WindowGroup is still visible. If I try to open the app again from the Home Screen the immersive space does not open.

  • @gchiste If there is only an immersiveSpace in the app struct and the home button is tapped, a new realityview is created. If there is an immersive space and a window group and the home button is tapped, the reality view is dismissed and none is created.

Add a Comment

@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.

  • And with regards to the second issue, this is behaving as expected. When the user presses the crown, your ImmersiveSpace scene is disconnected, and it is then purged from memory. When you re-open the app, the app already has a connected scene (the WindowGroup), so SwiftUI activates it. I recommend that you design your app in a way that gives users a path to re-open the immersive space from the window.

  • @gchiste The first issue is not happening anymore. Thank you for your time.

Add a Comment