RealityView attachment draw order

My visionOS 26.3 app displays a diorama-like scene in a RealityView in a mixed immersive space, about 1 meter square, with view attachments floating above the scene.

Each view attachment fades out after user interaction, by animating the view's opacity.

What I'm observing is that depending on the position of a view attachment relative to the scene and the camera, an unwanted cutout effect is observed (presumably because of draw order issues), as shown in the right column in the screenshots below.

YouTube video link of these sequences: https://youtu.be/oTuo0okKCkc (19 seconds)

My question:

How does visionOS determine the view attachment draw order relative to the RealityView scene?

If I better understood how the draw order is determined, I could modify my scene to ensure that the view attachments were always drawn after the scene, fixing the unwanted cutout effect.

I've successfully used ModelSortGroupComponent to control the draw order of entities within the RealityView scene, but my understanding is that this approach cannot be used with view attachments.

I've submitted FB22014370 about this issue.

Thank you.

Hey  @drewolbrich,

Thanks for filing this feedback. I wasn't able to replicate your experience, but I'm curious if you get the same result by replacing opacity(_:) with OpacityComponent?

Additionally, have you considered applying a subtle breakthrough effect on your views? This might mitigate the issue and could improve things if you expect your views to collide your content.

Are you able to replicate this behavior in a sample project that we could take a look at? Feel free to link it publicly here, or you can privately share any project with us in your Feedback Request. That'll help us better understand what's going on. If you're not familiar with preparing a test project, take a look at Creating a test project.

Thanks,
Michael

Hi @Vision Pro Engineer

I've created a sample app and attached it to FB22014370.

The sample app contains a README file with repro steps and a description of the issue.

I initially created a simpler sample app, and in that app, the issue could actually be fixed using breakthroughEffect as you suggested. (Incidentally, breakthroughEffect does not appear to fix the issue in the simulator.)

However, in the actual app I'm working on, breakthroughEffect surprisingly did not solve the problem, and the cutout effect was still visible in that app.

Through trial and error, I discovered that breakthroughEffect does not appear to help for scenes that use ModelSortGroupComponent and which also contain more than one ModelEntity with ModelSortGroupComponent assigned, and for which view attachments are positioned beyond the center point of the bounding box of model entities with the shared ModelSortGroup, from the perspective of the camera.

This scenario is demonstrated in the sample app.

In the sample app's README file, I've also included specific questions about the behavior of transparent view attachments when used with scenes that use ModelSortGroupComponent.

I tried your OpacityComponent suggestion and the view attachment draw order I observed was the same as when I used the opacity view modifier.

I appreciate any assistance you can provide to help address the unwanted cutout effect issue.

@Vision Pro Engineer

@drewolbrich Thank you for filing this bug report. This is helpful. At this time I don't have a workaround to address the unwanted cutout effect issue.

Thank you for responding.

Separately from this specific issue, I'd like to understand how RealityKit determines draw order between (not within) model sort groups, and between view attachments and scene geometry. (I'm aware ModelSortGroup's order parameter controls ordering within a group.) I can't find this documented anywhere.

How do you recommend I go about getting this question answered? I've already submitted a bug report, a code-level support request, and posted to the developer forums.

Hey @drewolbrich,

I took another look at the provided sample code project and if I understand things correctly, I don't think you need to control the draw order of the individual attachments. You have a non-coplanar scene and need to inform the system to either draw the model in front or behind your SwiftUI layers. You can use planarUIAlwaysBehind to instruct the renderer to draw a model’s mesh behind the SwiftUI layer that’s coincident with the mesh.

I performed the following change on your sample and fixed the issue:

- private let modelSortGroup = ModelSortGroup(depthPass: .prePass)
+ private let modelSortGroup = ModelSortGroup.planarUIAlwaysBehind

Can you try this and let me know if this works in your app?

If not could you provide an updated sample project that illustrates the issue using ModelSortGroup.PlanarUIPlacement to control the drawing order of SwiftUI views.

The best way to ask for documentation is by submitting feedback request and posting to the developer forums limiting both to a single topic. Please don't combine documentation requests with bug reports. Could you provide me with a feedback number requesting specific documentation?

Thanks,
Michael

RealityView attachment draw order
 
 
Q