Post

Replies

Boosts

Views

Activity

ECS custom component not being found when interact with it by a gesture
Hello, I am working in a custom component using ECS. My custom component is simple, has only an enum property and a float value. The System for this component just change the entity mesh color and put it to rotate. My component is being added in runtime on the reality view scene that I am working. The entities are being added correctly on scene, the colors are changing and it's rotating. But when I try to get this custom component by the tap gesture, it's saying that the entity does not have the component. I am adding the componets with this method: ... RealityView { content in if let mySceneEntity = try? await Entity(named: "MyScene", in: realityKitContentBundle) { await MM_InitializePointsOfInterest(sceneEntity: mySceneEntity, data: modelData) ... And the method that instatiate it is this: func MM_InitializePointsOfInterest(sceneEntity: Entity, data: ModelData) async { if let pinsGroup = await sceneEntity.findEntity(named: PointOfInterestSystem.pinsGroupID) { //find for the parent that will store the points of interest entities if let pinObject = try? await Entity(named: PointOfInterestSystem.pointOfInterestID, in: realityKitContentBundle) { //The json file do not have the UUID on it, so we generate it in when start to use data.pointsOfInterest.generateUUIDs() for poiData in data.pointsOfInterest.pointsList { let pin = await pinObject.clone(recursive: true) let pos = SIMD3<Float>(poiData.location[0], poiData.location[1], poiData.location[2]) / 100 //convert to cm await pin.setPosition(pos, relativeTo: nil) let poiComponent = PointOfInterestComponent(rotationSpeed: 0.5, type: poiData.type) await pin.components.set(poiComponent) await print("Has Component: \(pin.components.has(PointOfInterestComponent.self))") await pinsGroup.addChild(pin) print("Pin added at position: \(pos)") } } } I had some prints to debug, and they are working, showing that the entity was added to scene and that has the custom component that I made. But here, When I try to get the gesture: RealityView { ... }.gesture( SpatialTapGesture() .targetedToAnyEntity() .onEnded { value in print("Tap Gesture detected.") 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) } Is printing that the Point of Interest Component NOT FOUND! But the entities are on the scene rotating and with the colors that was set by the system of the ECS. If I add my custom component in an element that Already exists on scene (In reality composer pro) and try to access, I find it.
6
0
670
Nov ’23