Grab Component in VR template

Inventory for VR Player



Create BP Interface:


Open a folder called Interface
Create a BP interface, name as Grab, open it
image.png

Name the funtion inside as Grab, add variable Motion Controller in Input
image.png
Add a new function name as Release, repeat the same on Input
image.png


Set Inventory BP with actor:


Create a new folder called Blueprints

Create a BP Class actor, name as InventoryCube, open
Add Static mesh in component, set as Root component

Choose the mesh (cube in this case), collision presets as OverlapAllDynamic
image.png

go to Class Setting → Interface, Implement interface, add the Grab
image.png

Go the event graph, drag of double click interface release and grab functions in the graph
image.png
Create the graph as follow:
image.png
In BP folder, create BP class, type StaticMeshComponent, name a InvetnoryComponent. open it
image.png
Create the graph as follow:
Remark: BeginOverlap node renaming by Add Custom Event
image.png
Continue by adding variables GrabActor, and Controller to Ignore:
image.png

For Event Trick:
Remark: Self node by Get a reference by self
image.png


Attach inventory to VR pawn For Player:


Open VR Pawn, viewport,
Add InventoryComponentLeft under MotionControllerLeft,
Change it mesh to a sphere, scale down to fit in the camera mesh:
image.png

Collision Preset OverlapAllDynamic (to make sure not collide with motion controller)

Duplicate the inventorycomponent for Right hand

Go to Event Graph, end of begin play nodes, add follow:
image.png

In InputActipn Grab left and Right nodes, recreate the graph as follow:
image.png
Copy all nodes above apply on InputAction Grab Right, change motioncontroller, GrabActor (duplicate from Grableftactor) variables from left to right
image.png


Drag the InventoryCube BP in the scene, open VR preview

Now can snap the inventory cube on Vr component (controllers), can create other inventory elements besides cube to snap on the component/actor/character

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.