Switching between immersive spaces

I have 3 immersive spaces, and I'm trying to "jump" between them. Whenever I go from a space to the next one I try to dismiss the current one by executing await dismissImmersiveSpace() and right after await openImmersiveSpace(value: id). This is being performed inside of a Task, run on the click of a button. It seems like dismissImmersiveSpace is released before the actual space has been completely removed, as the next immersive space does not open. On the other hand, I added a manual waiting time between dismissing an immersive space and showing the next one, and everything seems to be working fine, which is why I suspect that this is a lifecycle issue of the dismissImmersiveSpace.

That being said, is there any way to listen to the actual state of the dismissed immersive space, so that I know when I can present the next one?

Is there any way around this without having to introduce a manual delay?

I'm completely new to SwiftUI and building in the apple ecosystem, so apologies if this doesn't help as I'm not fully sure why it would, but in my function I'm calling

{ 
await dismissImmersiveSpace()
switch await openImmersiveSpace(id: "MyFullSpace") {
    case .opened:
        myFullSpaceIsShown = true
    case .userCancelled:
        return
    case .error:
        return
    @unknown default:
        return
}

Perhaps the switch await will solve it?

Try it with this code:

//…

@State var anyImmersiveSpaceOpen: Bool = false

//…

//when Button Click
Task {
            if anyImmersiveSpaceOpen {
                await dismissImmersiveSpace()
                anyImmersiveSpaceOpen = false
            }else {
                if anyImmersiveSpaceOpen {
                    await dismissImmersiveSpace()
                }
                await openImmersiveSpace(id: id)
               
                anyImmersiveSpaceOpen = true


            }
        }

could you post your code with the manual delay that worked?

I tried many things but dismissImmersiveSpace always trumps all. However I think I found a convoluted workaround. In Reality Composer Pro I copied all my individual scenes into one master scene. Then in my immersive view I used @State to create several empty entities. In the RealityView make I loaded the master scene, then used findEntity by name to populate the @State entities, and content.added my first scene. I then used a tap gestures to set @State bools that RealityView update can use to switch to my other scenes. It's very convoluted to get around the dismissImmersiveSpace behavior of killing off both old and new scenes described above. I will say that the performance is very good and probably better than doing multiple async scene loads. Unfortunately this workaround involves keeping a lot of state in the immersive view. I would welcome a better suggestion.

Apple fixed this and at least in the latest simulator you can have a task to dismissimersivespace and then openimmrsivespace. The fix appears to have been to add a small delay to the dismiss. Therefore if you want to immediately switch scenes it is more performant to have scenes in a master scene and load that master in RealityView make and then use update to switch what the user sees. Of course if you don't mind a kind of fade out and fade in effect you can dismiss and open.

Hello,

it surely would be nice to be able to define transitions (animation, transition styles, etc) between spaces, that could play while loading.

I'm curious, what is the benefit you see in switching between immersive spaces compared to switching between views in one immersive space?

Switching between immersive spaces
 
 
Q