Language:
Page Info
Skill Level:
Engine Version:

Motion Controller Component Setup

You can add a Motion Controller as a component to your Pawn / Character, set which "Hand" it is supposed to represent. In the following document we will cover how you can set up your Virtual Reality project to make use of Motion Controllers.

Before going any further make sure that your VR Headset and Motion Controllers are plugged into your PC and required the drivers installed. See the VR Documents for information on how to get various VR headsets to work with UE4.

Motion Controller Setup

Setting up a VR project to make use of Motion Controllers requires adding a Motion Controller Component to your Pawn and configuring it. In the this section we will cover how you can quickly get Motion Controllers working with your project.

Please note this setup can be applied to any Pawn in any UE4 project.

  1. In the Content Browser open the Player Pawn Blueprint.

    Open_VR_Pawn.png

  2. Once the Blueprint is opened, navigate to the Viewport tab and in the Components section click on the Add Component button to expose the components that can be added to this Blueprint.

    Find_Components.png

  3. From the list that is shown search for the Motion Controller using the word Motion as the search term. When the Motion Controller component has been located, click on it to add it to the components list.

  4. Once the Motion Controller has been added, select it by clicking on it and then in the Details panel under the Motion Controller section make sure the Hand is set to Left.

    Setting_Up_Components.png

  5. To give the Motion Controller a visual representation in the world, select the Motion Controller Component in the Components panel and click the Add Component button to add a Static Mesh Component. Drag the Static Mesh Component on to the Motion Controller to parent it to the Motion Controller Component then, in the Details panel, assign a Static Mesh asset to the Static Mesh property of the new component.

    If your project does not currently have any Static Mesh assets, import one of your own meshes or click the Marketplace button in the toolbar to visit the Marketplace and download some assets to use in your project. If the Static Mesh you selected is too big or too small you can scale to your likening using the Scale section of the Transform section in the Details panel.

  6. Add another Motion Controller Component parented to the root and set it to be the Right Hand. Add a Static Mesh Component parented to the new Motion Controller Component and apply the right hand mesh to it..

    Finshed_MC_Setup.png

    In the image above, the the two cone shaped meshes have been moved apart to show that there are two of them. When setting up your project leave both Static Mesh Components at 0,0,0 so that they are located right on top of one another.

Working with Motion Controllers

The Motion Controller-specific input controls are available in the Palette panel in the Blueprint Editor.

If you search inside of the Blueprint Editor Palette using MotionController as the search term you will see all the available buttons and controls the Motion Controllers have available.

Working_With_MC.png

When looking at the available Motion Controller input options there is a capital L or R next to the name of what that value is supposed to control. This L or R means that this is for the Left or Right Motion Controller.

MC_Left_Right.png

Using Motion Controllers

In the following section we will set the Motion Controllers up so that when you press the trigger button on the Right-Handed Motion Controller a Blueprint containing a Static Mesh is spawned into the world, while pressing the trigger button on the Left-Handed Motion Controller will remove the mesh from the world.

  1. In the Content Browser create a new Blueprint named BP_Sphere and open it up by double-clicking on it.

  2. Navigate to the Viewport tab and add a new Static Mesh Component.

    Add_SM_Component.png

  3. Move the Static Mesh Component on top of the Default Screen Root and set the Static Mesh used to the ArcadeEditorSphere and compile and save your Blueprint.

    If you can not find the ArcadeEditorSphere make sure that you have the Engine Content folder enabled by going to View Options and then clicking on the Engine Content folder to enable it showing up in the Content Browser.

  4. Close the BP_Sphere Blueprint and open up your Pawn Blueprint.

  5. In the my Blueprint panel, navigate to the Event Graph tab and create a new Actor variable with the name Objects with its Variable Type to array.

    Create_New_Var.png

  6. This Blueprint is going to allow us to add and remove a specified object from the world when the trigger button on the Motion Controllers is pressed. To do this, inside of the Event Graph add and connect the following Blueprint nodes together. When completed you should have something that looks like the following image.

    Add_Objects_Setup.png

    The Spawn Offset was added to ensure that the objects could be seen while being placed in this example. The offset is not required and can be omitted by connecting the Return Value from the GetActorTransform node to the Spawn Transform input on the SpawnActor node. Add_Objects_Setup_Alt.png

  7. Select the Spawn Actor node and assign the BP_Sphere Blueprint that was created in step one to the Class input.

    Setting_SpawnActor_Up.png

  8. This section of the BLueprint will allow us to remove the objects that were placed in the world. To add this functionality, add and connect the following Blueprint nodes together. When completed you should have something that looks like the following image.

    Remove_Objects_Setup.png

    The keyboard input keys were placed in the graph for quick testing. You do not have to include those inputs for this to work with Motion Controllers.

  9. Compile and Save the changes to your Pawn Blueprint and then press the Play button. Once the level has started, try adding objects to the world by pressing the K key on the keyboard or by pressing the Right trigger on the Right Handed Motion Controller. To remove objects from the world, press the T key on the keyboard or press the Left trigger on the Left Handed Motion Controller which you can see demonstrated in the video below.

Training Streams