Meta XR SDK Snap Interactions

Meta XR SDK Snap Interactions

Since past 2 weeks, I have been trying to achieve LEGO like building block interactions on one of the projects with somewhat sinusoidal success pattern.

Introduction to Motion Graphics in p5.js - Learn by Digital Harbor ...

I was trying to do this via the latest Meta SDK's Snap Interactions.

To setup any snap interaction, you need to do to 2 things.

  1. Add a Snap Interactor component to your Snappable Object (SO)

  2. Add a Snap Interactable component to your Snap Location (SL)

➡️ You Snap Location has to have a Trigger Box Collider and would be as large as you want your Snap Zone to be. It would also have a Rigidbody.

And now you the SO will snap to your hand (Grabbable required) and also to the SL when you are inside the snap zone.

But I wanted to create building blocks where other blocks can snap on the front and the bottom faces. I used a grabbable cube and added 1 Snap Interactor to it as a child to make it a snappable object, and two Snap Interactables near each face to make them snap locations.

This worked fine as required but only for the simple Unity 3D cube and not for other block models I got from Sketchfab.

The problem was that since both the bricks would be having snap locations and are themselves SOs, they both try to snap to each other resulting in a condition called z-fighting. And thus when you snap, they launch in the z-axis like a projectile.

I tried to debug this a lot using the Interactable Debug Visual component and Interactor Events such as disabling one of the SLs or Interactors when any object has snapped but that was very limiting and did not produce the desired results.

Thus, I finally moved on to Unity's XR Interaction Toolkit and surprisingly, it just worked! More on that soon...😉