SteamVR

SteamVR

rwblodgett Feb 17, 2021 @ 9:57am
Laser Pointer UI Click not working in Unity
I'm having the hardest time getting SteamVR or Unity to recognize pointing a laser and clicking on a UI button on a canvas and triggering the button click event that is setup for that button.

When I use the XR framework and use an Oculus, it works.

When I use SteamVR, I am using the "actions" and "action sets". I tried adding the Valve InputModule to the Event System game object. I have a graphic raycaster on the canvas. I'm not sure what I need to do to get SteamVR to tie the trigger with clicking a button on a UI. I have setup the bindings so I have boolean action associated with the trigger. I also notice in the default bindings there is a InteractUI action that is also active. I'm lost on what are all the parts and pieces that need to be assembled to get SteamVR to use the trigger button to execute Unity button clicks. The Interactions_Example has no example showing pointing a laser and clicking a button on a canvas using the UI system of Unity.

I do have an action tied to the Menu button, which brings up the UI in game. That action is working. So it makes me think I have correctly setup the actions and action sets. However, there is something missing about tying the trigger action or the InteractUI action to a button click. I'm sure it's something silly.

I'm using Unity 2019.4.20 and SteamVR Unity Plugin 2.7.2.
Last edited by rwblodgett; Feb 17, 2021 @ 10:01am
< >
Showing 1-2 of 2 comments
rwblodgett Feb 19, 2021 @ 3:32pm 
Well, the way I got this working in the end was to implement a custom InputModule which extends the PointerInputModule, not BaseInputModule, and make sure I've got a GraphicRaycaster on the Canvas game object. Then in the Process method, make sure to call EventSystem.current.RaycastAll(data, m_RaycastResultCache); Then I make sure to look for click handlers on the resulting raycast objects. (Enter/Exit ones too) and call the click explicitly.

IPointerClickHandler clickHandler = raycastResult.gameObject.GetComponent<IPointerClickHandler>();
if (clickHandler == null)
clickHandler = raycastResult.gameObject.GetComponentInParent<IPointerClickHandler>();

if (clickHandler != null)
{
PointerEventData pointerEventData = new PointerEventData(EventSystem.current);
clickHandler.OnPointerClick(pointerEventData);

// only do one click event
break;
}

So, my application, which supports both Oculus and SteamVR, I can have Oculus using the XR framework, and SteamVR support with this custom InputModule. Have to support both legacy and new input systems in the Player Options.
droneattack Oct 1, 2022 @ 2:25am 
Why are you checking the parent object for Raycast result?
< >
Showing 1-2 of 2 comments
Per page: 1530 50