Hi I have added a 3D object into Reality Composer pro. What I want to do is, to show names on multiple points of the same object Just like Apples Diorama example. Following is my code
var body: some View {
@Bindable var viewModel = viewModel
RealityView { content, _ in
do {
let immersiveContentEntity = try? await Entity(named: "Immersive", in:realityKitContentBundle)
viewModel.rootentity = immersiveContentEntity
content.add(immersiveContentEntity ?? Entity())
//viewModel.updateScale()
// Offset the scene so it doesn't appear underneath the user or conflict with the main window.
//mmersiveContentEntity.position = SIMD3<Float>(0, 0, -2)
subscriptions.append(content.subscribe(to: ComponentEvents.DidAdd.self, componentType: PointsOfInterestComponent.self, { event in
createLearnMoreView(for: event.entity)
}))
//createLearnMoreView(for: immersiveContentEntity ?? Entity())
} catch {
print("Error in RealityView's make: (error)")
}
} update: { content, attachments in
print("UPDATE CALLED")
viewModel.rootentity?.scene?.performQuery(Self.runtimeQuery).forEach { entity in
guard let component = entity.components[PointsOfInterestRunTimeComponent.self],
let attachmentEntity = attachments.entity(for: component.attachmentTag) else { return }
//guard attachmentEntity.parent == nil else {return}
attachmentEntity.components.set(BillboardComponent())
//entity.addChild(attachmentEntity)
content.add(attachmentEntity)
attachmentEntity.setPosition([0.0, 0.5, 0.0], relativeTo: entity)
}
} attachments: {
ForEach(attachmentsProvider.sortedTagViewPairs, id: .tag) { pair in
Attachment(id: pair.tag) {
pair.view
}
}
}
}
I have added 2 transform entities into Reality Composer Pro like below and added custom components into it. Custom component only has 2 properties (name and description)
My ViewModel
is like this
import Foundation
import RealityKit
import RealityKitContent
import Observation
@Observable
final class ViewModel {
var rootentity: Entity? = nil
var showImmersiveContent: Bool = false
init(rootEntity: Entity? = nil, showImmersiveContent: Bool = false) {
self.rootentity = rootEntity
self.showImmersiveContent = showImmersiveContent
} }
My Problem is I cannot see my attachments on the 3D view when I go into immersive view first time. When I close the immersive view and re-open it, then I can see it. It looks like this subscription doesn’t fire when the immersive space loads 1st time.
subscriptions.append(content.subscribe(to: ComponentEvents.DidAdd.self, componentType: PointsOfInterestComponent.self, { event in
createLearnMoreView(for: event.entity)
}))
Does anybody know how to resolve this?