How To : Unity Vr Basics 2023 – Poke Interactor

Since I last covered the XR Interaction Toolkit, Unity has added an all new Interactor! Say hello to the Poke Interactor! As the name suggests, the XR Poke Interactor is responsible for allowing interactions specifically around poking.

Making A XR Poke Interactor

To make a XR Poke Interactor, we need to do the following.

  • Expand the XR Origin in the scene and locate the Left/Right Controller
  • Create an empty GameObject and name it ‘Poke Interactor’ and make it a child of the Left/Right Controller
  • Select the newly create Poke Interactor
    •  Add New Component ‘XR Poke Interactor’
  • Repeat this for the opposite controller so both have XR Poke Interactors
Believe it or not, that’s all there is to setting up a XR Poke Interactor.

XR Poke Interactor Attributes

Let’s touch on some of the attributes associated with the XR Poke Interactor.

  •  Interaction Manager – This manager is in charge of all interactions between the interactable object and the XR Poke Interactor.  
  • Interaction Layer Mask –  If you want to have only certain objects be interactable, you would use this layer mask to set that up. The default setting is to allow all interactable objects.
  • Attach Transform –  This is the Transform that the XR Poke Interactor will use to perform it’s interactions from. Unlike other interactors, the Poke Interactor doesn’t necessarily attach anything to itself, but instead performs simple interactions with other interactables.
  • Poke Depth – Depth threshold where an interaction can be considered a poke.
  • Poke Width – Width threshold where an interaction can be considered a poke.
  • Poke Select Width – Width threshold where an interaction can be considered a Poke Select.
  • Poke Hover Radius –  Radius threshold where an interaction can be considered a Poke Hover
  • Poke Interaction Offset – Distance along the poke interactable interaction axis that allows for a poke to be triggered sooner/with less precision.
  • Require Poke Filter –  Denotes whether valid targets will require a poke filter or not. (Will cover poke filters more later in this post)’
  • Enable UI Interaction – Denotes whether the Poke Interactor will be allowed to interact with UI objects.
Outside of these attributes, we also have our standard Interactor Events that can add functionality based on hovering enter/exit and select enter/exit.
 
Now let’s create something to poke!

Fixing Our Attach Point

Before we poke something, we need to make sure it’s poking from the correct position. For this example, I’m going to choose the Index finger to poke from. Luckily, we already have an object that is at the tip of our index fingers. Opening up the Left/Right Hand prefab, we’ll be greeted by this.

Expanding out the hand, we can see that there is a object at the very tip of the finger called ‘hands:b_I_index_ignore’. Since this is already at the very tip of the index finger, it will be perfect to use as our attach point.

The only problem is that our hands do not start off in the scene. Instead, they are generated at the beginning of the scene by our XR Controller scripts. In order to assign the tip of the index finger, we’re going to need a script.

  • Select the Left/Right hand prefab
    • Add Component ‘Script’ and call it ‘SetPokeInteractableToFingerAttachPoint’

 

The script here is very straight forward. We choose an Attach Point from our hand and it will assign it to the attachTransform in the XR Poke Interactor. 

Just remember to assign the index finger to the empty slot in the editor!

With that, let’s make a poke-able object!

XR Simple Interactable & XR Poke Filter

In order to see what the XR Poke Interactor does, let’s make a XR Simple Interactable and XR Poke Filter to see how the Poke Interactor works.

  • Create a Cube and call it ‘Poke Interactable’
  • Add Component ‘XR Simple Interactable’
  • Add Component ‘XR Poke Filter’
  • Scale = (0.1, 0.1, 0.1)
  • Move cube in front of XR Origin to make it easy to interact with

Let’s touch on the Simple Interactor. This is the most basic use of a Interactable that we can construct. With it, we can use the Hover Entered/Exit and the Select Entered/Exit to display how our Poke Interactor is working. To do that, I’ve chosen some materials to change colors for Hover Entered/Exit and Select Entered/Exit. 

Next is the XR Poke Filter. This is required from our XR Poke Interactor in order to have Poke Interactions. 

  • Interactable – This will be the Interactable script that the Poke Filter will use to signal interactions.
  • Poke Collider – This is the collider used by the Poke Filter to determine interactions occurring.
  • Poke Configuration
    • Poke Direction –  This is used to determine which direction a poke must occur in order to be considered a poke interaction. For example, setting to Negative Y would require the Poke Interactor to be moving from a positive Y position to a negative Y position relative to the current objects orientation.
    •  Interaction Depth Offset –  This can be used to trigger a poke interaction sooner at the cost of precision.
    • Poke Angle Threshold – The maximum allowed angle from the poke direction axis that will trigger a select interaction.

If we start up the scene now, you’ll see that the box will change to blue when hovered and yellow when a Select action is triggered. Note that since I’ve set mine to negative Y, it will only trigger a selection when coming in from the top of the object and moving in a negative Y direction.

Canvas Interactions

The last interesting thing we can do with the poke interactor, is interact with our UI Components. For this example, just create a UI Canvas in World Space. Add to it buttons and sliders so you can explore how these interactions work with the Poke Interactor. 

Conclusion

Out of all the functionality for the Poke Interactor, I find the canvas interaction to be the most useful. Although I would like for it to work well with buttons and switches, it seems that the Poke Interactor leaves out physics interactions. When we go to push a button or switch, we would have to check for when it enters a ‘Select’ state and perform some action then. If we instead used a physics based button, it would only need to check if the button has been pushed in far enough, allowing for more variety in our buttons and switches.