Unreal Engine 4.13 introduces the official Virtual Reality template made entirely in Blueprint. The template further simplifies getting started with VR in UE4. In this guide I go through the features and several tips on how to go beyond the template to build your own VR projects.
- 1 HMD / Gamepad Teleportation
- 2 Motion Controller Teleportation
- 3 Project Optimized for VR
- 4 Get Started
- 5 Migration to your own project
This VR template is targeting desktop and console only. It supports Oculus Rift, HTC Vive and PlayStation VR out of the box. Other platforms such as GearVR are not officially supported, but with some changes to the project settings (following Android/GearVR Documentation) you can get this template running on your GearVR device.
To get started, simply download Unreal Engine 4.13 through the Epic Games launcher and create a new project using the Project Wizard. The template is listed as “Virtual Reality” in the Blueprint-section. At the time of 4.13 there is no C++ version of this template.
Unlike the traditional templates shipped with the engine, this includes two maps! This separates the different types of locomotion for the available hardware features (eg. with or without motion controllers) you can find both maps under VirtualRealityBP/Maps/ in your Content Browser. The differences and features of each implementation are detailed below.
HMD / Gamepad Teleportation
A simple teleport locomotion where you can use the Gamepad or keyboard to initiate a move. Press and hold to pin your teleport destination, you may now either look at the new direction of your teleport (this will update your neutral rotation) or use the thumbstick on the gamepad to set a new neutral rotation of your character.
Motion Controller Teleportation
This type of teleportation required a motion controller. Point in the direction and press the thumb control (eg. Touchpad on the Vive) to initiate the move. You can use the outer edges of the touchpad to set a new neutral rotation.
This type of locomotion utilizes a navigation mesh. the navmesh is used to filter for valid destinations while teleporting. See Blueprints migration section for more info. (Press “P” to visualize the NavMesh in the editor viewport)
Alternate Rotation Mode
The PlayStation Move controller doesn’t have an axis input, so I built an alternate rotation mode that you can optionally use for other platforms such as Vive as well. You can can manually enable this for other platforms than the PS4 by setting UseControllerRollToRotate in the MotionControllerPawn Blueprint.
Room-scale is visualized around the teleport target. The square outline mesh is only rendered when Room-scale setup was run successfully on the Vive. The room-scale can be rotated using the thumb controls on the motion controller or by using the alternate rotation mode described above.
Using the trigger controls you can grab and move the simulated boxes on the table. When near a grab-able object the controller shakes and the hand mesh takes on a different pose.
It may be interesting to know the collision (eg. to punch the boxes) on the hands are only active while the trigger is pressed (the hand looks like a fist)
Adding your own objects to grab
To add new types of objects you need to implement the Blueprint Interface (located at VirtualRealityBP/Blueprints/PickupActorInterface) at your own Blueprint that you want to make grab-able by the VR hands. There are docs available on how to implement blueprint interfaces.
Project Optimized for VR
The template comes with a number of rendering optimizations for VR. For more info on optimizing your own current project for VR, check out the VR Guide for UE4 (Specifically the Performance Considerations section) In the Rendering & Performance Settings I explain how to migrate these over to your own project.
The simulated cubes (blue) cast and receive (dynamic) shadows which is a usually costly feature. However, this cost can be cut in half by enabling “Single Sample Shadow from Stationary Lights” on your movable Actors. This feature makes shadow receiving on dynamic objects much cheaper at the cost of some quality. It doesn’t work for all scenarios, but is worth playing around with for your dynamic objects for potentially great performance gains.
Simply down the Engine version 4.13 or up from the Epic Games Launcher. Create a new project and select “Virtual Reality” in the Blueprints category. For additional help on getting started I recommend reading up on my VR Guide for Unreal Engine 4.
To check the template input mapping you can simply open up Edit > Project Settings… and browse to category Input. They should be fairly self-explanatory.
- Gamepad Mappings
- Gamepad bottom face-button (eg. A on Xbox controller) OR Enter-key = Initiate teleport
- Gamepad Left Thumbstick = Change orientation during teleport
- MotionController Mappings
- Touchpad Press = Initiate teleport
- Touchpad Axis = Change orientation during teleport
- Trigger = Grab Object
Walkthrough by REEL Pictures
I quite like the following video walk-through of the VR Template by REEL Pictures. It guides you through the available features in the motion controller level.
Migration to your own project
Many of you may be looking to integrate some of the template features into your own existing project. I’ve list some potential issues and most important files to migrate.
Using UE4’s Built-in Migrate Content feature you can easily move over content and dependencies into your own project. You can right-click the Pawn Blueprint of the teleportation type you wish to use in your own project and selecting Asset Actions > Migrate.
The motion controller based locomotion requires a NavigationMesh to filter for valid teleport destinations. To override this behavior with your own filtering is pretty easy and you should start by looking at the BP_MotionController Blueprint’s TraceTeleportDestination function.
Rendering & Performance Settings
To migrate over the performance settings from the template check out the /Config/ folder of the template folder. In particular the entire DefaultScalability.ini file and the [/Script/Engine.RendererSettings] section of DefaultEngine.ini contain useful scalability for your VR project.
That is all for the VR Template guide! Have fun in VR!