Widget interaction: How do I get which instance of widget interaction clicked a button?

Question

So I am making a menu for our VR toolkit, and in doing so I need to know which hand / vr controller / widget interaction instance clicked the button menu, but I am coming up short in terms of implementation.

The menu shows different tools that can be spawned (measuring tool, painting tool, camera tool) and since people are either left handed or right handed, it would be preferable to spawn the tool in the hand that clicked the button.

I'm currently thinking that the solution lies in giving each widget interaction (hand) a unique pointer index, but I don't understand how to read the pointer index value on the button click event.

Any help would be appreciated, thanks.

Posted Apr 15, 2019, 7:13 AM UTC

29
Daelus1•

So you have a 3d widget in world space that the VR controllers interact with and you want to know which one is the one that sent the interaction, right?

You could override the "on key down" event in the widget, do a "get key" on the in key event, and check what the key is. There's motion controller L&R under gamepad. If there's more than one relevant button that can interact with menus you might need to build a custom function to compare all the various buttons. I don't see a simple "is left/right hand" filter. Not sure if this is the ideal way to do it, or if it'll get what you want. I haven't done much experimenting in VR.

Alternatively, you could do a sort of active/inactive controller and set that each time you press an actual button on the controller in your player character and reference against that whenever the widget event gets triggered.

2
Ridemyface2016•

I was wondering if the "on key down" thing would work but wouldn't it just give you the mouse button, as the interaction component is simulating mouse key press? I could be wrong!

1
Daelus1•

That would be on mouse down, there's a separate event for on key down and you can definitely do gamepads and keyboards.

1
failbyeOPDev•

> So you have a 3d widget in world space that the VR controllers interact with and you want to know which one is the one that sent the interaction, right?

Correct.

This is probably they way I have to go. I was hoping there was some simple way to get information on who or what caused this WidgetButton to trigger OnClick()

1
Ridemyface2016•

Maybe not the best way to do this but could you put an enum in your player controller for left/right which gets set every time the player presses the interact button, then in the widget BP get the player controller and switch on the enum?

Or maybe better just have a reference to the actual motion controller BP that was last pressed.

1
failbyeOPDev•

Sorry for late reply.

I do have an enum in the motion controller (Blueprint that defines the hand) that tells if it is the left or right hand. However, since the interaction component simulates a mouse down event, I don't see any obvious or simple way to retrieve "which instance of widget interaction simulated the mouse down event".

1
Ridemyface2016•

I actually did this yesterday and it works great. In the VR pawn I have an enum called 'active controller'. The left and right input events are in the pawn and I just set the enum to whichever one was pressed last. Then in the widget I do - get player pawn>cast to VR pawn>get active controller>switch on controller. I'll add a screenshot in a min.

2
Ridemyface2016•
2
failbyeOPDev•

Thank you! Sat this up today and it works beautifully. I'm still slightly concerned about the edge case where a user mashes all the buttons together at the same time but until it poses a significant problem, I'm going to leave it as is for now.

2