Entity HoverEffect Fired When inside Another Entity Collider

Hi folks, I’m new to Vision Pro stack, still trying to learn all the nuances. Here is a problem I can’t seem to find an answer.

I placed entity A( a small .02 radius sphere) inside entity B( size:.1 box). Both entities have HoverEffectComponent, and both inputcomponent is set to .direct. Entity A is NOT a child of Entity B. When I direct touch Entity B, I noticed that Entity A’s hover effect is fired as well. This only happens if Entity A‘s position is inside Entity B. The gesture that is only targeted at Entity A doesn’t work either. I double checked Entity A collider which sits inside entity B collider, my direct touch shouldn’t have trigger its hove effect. Having one collider inside another seems to produce unpredictable behavior? Thanks in advance 🙏🙏🙏

Context: I’m trying to create an invisible bound around Entity A, so when my hand approaches the bound to grab Entity A, a nice spotlight hover effect would fire first on the bound before hand reaching entity A.

Hi @SandraF,

Your intuition is correct. The very simplified algorithm is to cast a ray from the point of the event to the collision shapes.

In my experiment, doing what I think you are describing. I consistently get events on both entities if I pinch 'inside' the outer entity on the inner entity. And as expected the outer entity gets events if my pinches are outside the inner entity but on or in the outer entity. Wow that's a mouth full.. :)

Here is the code for my view's body, in case it's helpful.

    var body: some View {
        RealityView { content in
            entityA = ModelEntity(mesh: .generateSphere(radius: 0.02), materials: [UnlitMaterial(color: .purple)])
            
            entityA.components.set(CollisionComponent(shapes: [.generateSphere(radius: 0.02)]))
            entityA.components.set(InputTargetComponent(allowedInputTypes: .direct))
            entityA.components.set(HoverEffectComponent())
            
            entityB = ModelEntity(mesh: .generateBox(size: 0.1), materials: [SimpleMaterial(color: .orange.withAlphaComponent(0.25), isMetallic: true)])

            entityB.components.set(CollisionComponent(shapes: [.generateBox(size: SIMD3<Float>(0.1, 0.1, 0.1))]))
            entityB.components.set(InputTargetComponent(allowedInputTypes: .direct))
            entityB.components.set(HoverEffectComponent())

            content.add(entityA)
            content.add(entityB)
        } update: { content in
        }
        .gesture(TapGesture().targetedToEntity(entityA).onEnded { _ in
            print("entityA tapped")
        })
        .gesture(TapGesture().targetedToEntity(entityB).onEnded { _ in
            print("entityB tapped")
        })
    }

Thanks for the response! If I were to implement a design as below: where my hand can grab entityA that sits inside entityB that is transparent, when the hand is close to the entity B bound, a spotlight effect will fire. Seems like having both entity A and Entity B as input target wont work? Should I shoot a raycast from the index finger and link the hit position on the entity B collider to a custom shader material? I'm still quite new to Swift, wondering if there is a simple solution?

Entity HoverEffect Fired When inside Another Entity Collider
 
 
Q