I am learning to use RealityView
, and I will encounter an error when using attachments
: 'init(make:update:attachments:)' is unavailable in visionOS
import SwiftUI
import RealityKit
struct MoonOrbit: View {
var body: some View {
RealityView{ content, attachments in
async let earth = ModelEntity(named: "Earth")
if let earth = try? await earth{
content.add(earth)
}
} attachments: {
Text("Earth")
.tag("earth_label")
}
}
}
I checked the interface documentation and everything is fine.
It's frustrating and makes me unable to continue.
I found the answer here, but I really didn't notice any difference the first time
Old:
New:
Finally, I found that in the
attachments
method, I also need to useAttachment
to nest it.