Hello,
To me, it does not seem to be entirely clear why, when I'm trying to display my attachment, no matter the positioning, it will always be hidden/covered by my visionOS app window. I'm trying to achieve displaying the attachment one layer above/in front of the window. When my head isn't directed towards the window I can see the attachment but else it's covered by it.
I appreciate any help!
ContentView.swift
import SwiftUI
import RealityKit
struct ContentView: View {
@Environment(\.openImmersiveSpace) private var openImmersiveSpace
public var body: some View {
VStack {
Text("Hello World")
.font(.largeTitle)
Button("Start") {
Task {
await openImmersiveSpace(id: "AppSpace")
}
}
}
}
}
ImmersiveView.swift
import SwiftUI
import RealityKit
struct ImmersiveView: View {
var loader: EnvironmentLoader
public var body: some View {
RealityView { content, attachments in
content.add(try! await loader.getEntity())
let headEntity = AnchorEntity(.head)
content.add(headEntity)
if let text = attachments.entity(for: "at01") {
text.position = [0, 0, -0.25]
headEntity.addChild(text)
}
}
attachments: {
Attachment(id: "at01") {
Text("Hello World!")
.font(.extraLargeTitle)
.padding()
}
}
}
}
App.swift
import SwiftUI
@main
private struct App: App {
@State var loader = EnvironmentLoader()
public var body: some Scene {
WindowGroup {
ContentView()
}
ImmersiveSpace(id: "AppSpace") {
ImmersiveView(loader: loader)
}
.immersionStyle(selection: .constant(.progressive), in: .progressive)
}
}
Hi @XWDev
Thanks for adding the images. They helped me understand. I did some research and learned that only mixed
immersion supports rendering entities (attachments are entities) in front of a window. That is, a window will always obscure an entity in progressive
or full
immersion. If you'd like support for rendering an entity in front of a window in full or mixed immersion, please file a feature request via feedback assistant and detail your use case. Be sure to focus on the outcome. For example, you may say, "I want to create a heads up display in a fully immersive space", rather than saying, "I want to place an entity in front of a window".