Object grabbing

In this section, we'll learn about how object grabbing is implemented. The following screenshot of the VR template shows the hand grabbing a cube object:

The VR template created Blueprint Interface named PickupActorInterface. The Blueprint Interface only contains Function names and parameters and is used to share standard communication protocols between different types of Blueprints.

To create a Blueprint Interface, click the Add New button in Content Browser, and, in the Blueprints submenu, select Blueprint Interface, as shown in the following screenshot:

Double-click PickupActorInterface, which is located in the VirtualRealityBP/Blueprints folder, to open the Blueprint Interface Editor. The next screenshot shows that PickupActorInterface has two Functions named Pickup and Drop. The Pickup Function has an input parameter named AttachTo, which is of the Scene Component type:

We need to add PickupActorInterface to the Blueprint classes that can be grabbed by the BP_MotionController Blueprint. To do this, click on the Class Settings button of the Blueprint Editor. Then, in the Details panel, go to the Interfaces category, click on the Add button, and select PickupActorInterface, as shown in the following screenshot:

When you add an interface to a Blueprint, it becomes possible to implement the interface Functions in the Blueprint. The next screenshot shows the Functions of 
PickupActorInterface in the Event Graph of a Blueprint:

You can check whether Actor Reference implements the interface by using the Does Implement Interface Function, as shown in the following screenshot:

Double-click BP_PickupCube, which is located in the VirtualRealityBP/Blueprints folder, to see how object grabbing was implemented in this Blueprint. The next screenshot shows Event Pickup. The AttachTo input parameter receives a reference to the Motion Controller Component of the BP_MotionController Blueprint. Event Pickup turns off the physics simulation and attaches the root Component of BP_PickupCube to the Motion Controller Component:

The following screenshot shows Event Drop, which turns on the physics simulation and detaches BP_PickupCube:

If you want to create another Blueprint that can be grabbed by the Motion Controller, then you need to add the PickupActorInterface interface to the Blueprint. Then, in the new Blueprint, you can implement Event Pickup and Event Drop with a different way of how an instance of this Blueprint can be grabbed by the Motion Controller.

Object grabbing starts when the player triggers the GrabLeft or GrabRight Events. These Events are implemented in the MotionControllerPawn Blueprint. The next screenshot shows the GrabLeft Event. When the trigger is Pressed, the Grab Actor Function is called, and when the trigger is Released, the Release Actor Function is called. Both Functions can be found in BP_MotionController:

The following screenshot is from the Grab Actor Function of BP_MotionController. The Get Actor Near Hand Function of BP_MotionController returns the nearest overlapping Actor that implements PickupActorInterface. The reference to the Actor returned from the Get Actor Near Hand Function is stored in the Attached Actor variable and is used to call the Pickup Event that will attach it to Motion Controller:

The Release Actor Function of BP_MotionController calls the Drop Event of the attached Actor and resets the variables used when an object is grabbed, thereby finishing the grab movement.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset