visionOS RealityView attachment SwiftUI controls don't always respond to user interaction

My visionOS app has a RealityView with an attachment containing SwiftUI controls, and occasionally the controls in the attachment don't respond to user interaction.

Is this a known issue?

Is there a workaround?

Are RealityView attachments only intended to be output only?

Using visionOS 1.0 beta 3 (Xcode 15 beta 8), I've reproduced this problem with a small standalone Xcode project. I submitted the issue as FB13143132 with lovingly hand-crafted artisan repro steps. The Xcode project is also available at https://github.com/drewolbrich/AttachmentControls

Thank you for investigating this issue.

Screenshot my use case:

Answered by drewolbrich in 771449022

This was fixed in visionOS 1.0 beta 4.

This might be the same issue I'm seeing with attachments in the immersive space I mentioned over in this thread. I noticed this happening only with the latest beta 8 and filed a feedback with Apple.

Since I needed to find a workaround for this issue myself, I played around a little more. As suspected, this definitely is a race condition during the initial RealityView setup. I have a test project set up that adds two buttons and a toggle to the ImmersiveView in Xcode's template project. When I add

try! await Task.sleep(nanoseconds: 100 * NSEC_PER_MSEC)

at the end of the view’s make closure, all three UI elements are always active in the visionOS simulator on my MBP M2 Pro, 8+4 cores, 16 GB.

When I go down to 50 * NSEC_PER_MSEC, all of the UI elements work (most of the time - I’ve had a case where two of the three were active, but the third one, that is added last, wasn’t).

When I go down to 30 * NSEC_PER_MSEC, all of the UI elements sometimes work.

When I go down to 20 * NSEC_PER_MSEC, none of the UI elements work.

By "if I later update the attachment to display a different set of controls", what I meant is that the reality view's RealityViewAttachments and my attachment's corresponding entity remains unchanged, but my attachment's view is repopulated with a different set of controls depending on several if/then statements. The set of controls can also change dynamically over time in response to user action. (I only ever have one attachment.)

I should have time tomorrow to experiment with this more. Thank you for the suggestions.

@atbf fyi, in the feedback that I submitted for this bug (FB13143132) an Apple engineer responded. They said they were able to reproduce this issue, they believe they have addressed the problem, and a fix will be included in an upcoming release. ❤️

This was fixed in visionOS 1.0 beta 4.

Accepted Answer

This was fixed in visionOS 1.0 beta 4.

visionOS RealityView attachment SwiftUI controls don't always respond to user interaction
 
 
Q