Simple Tap Gesture to trigger Reality Composer animation

I wanted to make a very simple AR Viewer that is based on Reality Composer and RealityKit, following Apple's video "Building Apps With RealityKit" session 605. I started with an XCode Project the basic Box AR anchored to the floor, it has Reality Project loaded with a Box. That part is working fine.


I modified the RC Project and adding my own USDZ asset.


What I would like to know is just super basics:

- To be able to register Tap Gesture to trigger my Reality Setup (run animation)

- Ability to Modify Material, maybe changing color

- Adding Occlusion Material into Entity


So far I got to this by watching Apple's Video:

- I cannot seem to get a print out of where I tap on screen. I thought it would be fairly simple.

- I cannot seem to be able to see my object with Occlusion Material. I mean it is probably already in the scene but not sure where I anchor it exacly.


What is wrong exactly with my code?



import UIKit
import RealityKit

class ViewController: UIViewController {
   
    @IBOutlet var arView: ARView!
   
   
    override func viewDidLoad() {
        super.viewDidLoad()
       
        // Load the "Box" scene from the "Experience" Reality File
        let boxAnchor = try! Experience.loadBox()
       
       
        // Add the box anchor to the scene
        arView.scene.anchors.append(boxAnchor)
       
       
        // Occlusion Plane
        let planeMesh = MeshResource.generatePlane(width: 2.5, depth: 2.5)
        //let planeMesh = MeshResource.generateBox(size: 2.0)
       
        let material = OcclusionMaterial()
       
        let occlusionPlane = ModelEntity(mesh: planeMesh, materials: [material])
       
        occlusionPlane.position.y = 1.5
       
        // add to anchor
        boxAnchor.addChild(occlusionPlane)
       
       
       
       
       
    }
   
   
   
    // Hit Testing
   
    @IBAction func onTap(_ sender: UITapGestureRecognizer){
        let tapLocation = sender.location(in: arView)
       
        if let blah = arView.entity(at: tapLocation){
            print(blah.name)
        }
    }
}

have you tried to add an usdz asset with animation? i'm having similar issues

The entity(at:) documentation states that "The method ignores entities that lack a

CollisionComponent
".


Are you sure that the entity you are tapping has a collision component?

Hmm I am sure all of my objects have been given Physics inside Reality Composer. Do I need to do anything else like maybe enabling GameController or something in order for Tap / Raycast Tap to work and register?

Yes, USDZ with animation is what I put into the Reality Composer project inside this simple basic template. It shows up as AR, but I don't think tap is working.

UPDATE:


Ok, I tested the project again today after restarting my Mac and somewhat the Tap Gesture that I setup using RC now working! Which is strange. I also made a new project with USDZ + animation that should trigger when tapped, and that's working also! So that part is good.


However the IBAction tap function to "print the name of object" still does not work. I am wondering if we need to "override" the tap gesture with RealityKit?

Simple Tap Gesture to trigger Reality Composer animation
 
 
Q