I just programmed that functionality into my game. So here is what I did:
I have a CollisionComponent that collides with WidgetComponents (Make sure the ‘UI’ Collision Profile is set up correctly). And I have a WidgetInteractionComponent with the InteractionSource set to Custom.
Every tick I am sweeping the CollisionComponent to where my finger is. The SweepHitResult is the set as the CustomHitResult for the WidgetInteractionComponent. Make sure the CollisionComponent is not attached to your MotionControllerComponent, otherwise the CollisionComponent will have been moved by the MotionControllerComponent already and performing the sweep will do nothing because of that.
After I set the CustomHitResult, I check whether the sweep hit a WidgetComponent and the WidgetInteractionComponent’s LastHitResult has the same WidgetComponent and the WidgetInteractionComponent IsOverHitTestVisibleWidget. If that is the case, I call PressPointerKey for the LeftMouseButton. Otherwise I call ReleasePointerKey for the LeftMouseButton.
The reason to check IsOverHitTestVisibleWidget is that it takes a tick or two for the WidgetInteractionComponent to fetch the widgets and PressPointerKey or ReleasePointerKey can not click any buttons, if the WidgetInteractionComponent is not OverHitTestVisibleWidget.
Hey guys, I’m hoping somebody can help me out with setting up vr “touch screen” interactions.
In my game, the player has a tablet that they can take out to access objectives, map, inventory etc. I want the player to be able to interact by touching the screen with the index finger on their virtual hand.
I’m not sure how to handle / set up this interaction though.
I was thinking I could use a Widget Interaction component, but I can’t figure out how to have it essentially ‘click’ the button without the player having to pull the trigger.
Other than that, I’m not sure how to progress. Any help would be really appreciated.
Using the Virtual Reality UE4 template.
Create a socket on the MannequinHand_Right skeleton asset.
In BP_MotionController, Create a WidgetInteraction and a Sphere collision component, have them attached to the Scene component. Set the sphere collision presets to UI.
Scale the sphere and WidgetInteraction to finger size.
I used (X=0.050000,Y=0.050000,Z=0.050000) for scale of the sphere and (X=0.500000,Y=0.200000,Z=0.200000) of the WidgetInteraction, I also set the interaction Distance to 25 of the WI.
Then at begin play use a timer by create event or use game tick to do this:
If your touch collision is a sphere and your widget is a plane you can do it accurately with overlap and line trace.
Rotation does not matter for a sphere, and when it overlaps, do a line trace across two sides of the sphere in opposite direction of the widget component.