Portals and ImmersiveSpace?

I've added a simple visionOS Portal to an app's initial WindowGroup (a window with an attached portal is all that is displayed), but I've had troubles adding a portal to an ImmersiveSpace.

For example, using the boilerplate code that Xcode creates for a mixed spatial experience, I'd like to turn on & off the ImmersiveSpace which has a portal in it.

So far, the portal isn't showing up.

Is it possible to add a portal to an ImmersiveSpace? Are there any restrictions on where portals can be added?

Yes you can. I managed to do it using a regular attachments. But be aware that the attachment API has changed from the original documentation: https://forums.developer.apple.com/forums/thread/736588

So in my RealityView that is my immersive space i add after content.add:

// Portal is created 2m from you with root of immersive space being where the user stands.
        if let portalCenterAttachment = attachments.entity(for: "portal_center"){
                    portalCenterAttachment.position = [0, 1.25, -2]
        immersiveContentEntity.addChild(portalCenterAttachment)

And then after closing your RealityView you need to create the attachment using this new syntax:

 attachments: {
            Attachment(id: "portal_center") {
                MyPortalView()
            }

MyPortalView() is your RealityView with the makeWorld() and makePortal() in it. I think that all still works as descibed in: https://developer.apple.com/videos/play/wwdc2023/10081

Portals and ImmersiveSpace?
 
 
Q