Hey @gchiste thanks for your answer.
So, I made the test that you asked, and the answer is NO, the name that I add on the function that instantiate the entities is not the same as the name of the entity that the gesture get.
I made another test already, that was instead of add the entities on my func, I return an array of entities with all the elements.
And when I do it:
if let pinsGroup = erzbergSceneEntity.findEntity(named: PointOfInterestSystem.pinsGroupID) {
x.forEach{ e in
print(e.components.has(PointOfInterestComponent.self))
print(e.name)
pinsGroup.children.append(e)
}
}
It shown the name that I added and the component on it, but still seeing a different name when I interact with the entity on scene by TAP Gesture.
I don't know if because I am adding the elements inside of my reality view if. I need to refresh something. Did you have any tip?
Full Reality View code:
var body: some View {
@Bindable var modelData = modelData
RealityView { content in
// Add the initial RealityKit content
if let sceneEntity = try? await Entity(named: "EScene", in: realityKitContentBundle) {
// Add an ImageBasedLight for the immersive content
guard let resource = try? await EnvironmentResource(named: "ImageBasedLight") else { return }
let iblComponent = ImageBasedLightComponent(source: .single(resource), intensityExponent: 0.25)
sceneEntity.components.set(iblComponent)
sceneEntity.components.set(ImageBasedLightReceiverComponent(imageBasedLight: sceneEntity))
print("Adding Points Of Interest...")
let x = await MM_InitializePointsOfInterest(sceneEntity: sceneEntity, data: modelData)
if let pinsGroup = sceneEntity.findEntity(named: PointOfInterestSystem.pinsGroupID) {
x.forEach{ e in
print("Has POI Component? \(e.components.has(PointOfInterestComponent.self)) - with name: \(e.name)")
pinsGroup.children.append(e)
}
}
content.add(sceneEntity)
}
}
.gesture(tap)
}
var tap: some Gesture {
SpatialTapGesture()
.targetedToAnyEntity()
.onEnded { value in
print("Tap Gesture detected on: \(value.entity.name).")
if let poiComp = value.entity.components[PointOfInterestComponent.self] {
print("Point of Interest Component Id: \(poiComp.id)")
//let p : PointOfInterest = modelData.pointsOfInterest.pointsList.first(where: {$0.id == poiComp.id})!
//print(p.name)
} else {
print("Point Of Interest Component NOT FOUND!")
}
let curScale = value.entity.transform.scale.x
value.entity.transform.scale = curScale > 1 ? SIMD3(1,1,1) : SIMD3(1.4, 1.4, 1.4)
}
}