UE4 Code Samples: The Essentials

Oculus Developer Blog
Posted by Spencer Miller
August 6, 2020

Creating a new VR experience is a thrilling adventure, but it can be daunting if you don’t know where to begin. Code samples can help you on the first steps of your journey. Particularly in a new knowledge space (like VR), sample projects provide an easy path to experimentation and can act as a springboard for your ideas. When we launch new features for Oculus developers, we include these samples to demonstrate the concept and to help with integration into your own projects. Today, we’re showcasing a new batch of Unreal Engine 4 samples for a variety of essential VR functionality, from locomotion to platform permissions to rendering legible text.

Most of the samples described below have a companion video that walks through how the project is constructed, and that’s generally a good place to start. All code samples are included in the Oculus UE4 Engine Integration.

Locomotion and Interactions

The locomotion and interactions sample showcases a handful of common modes for moving the player around. Also included are some interactable objects, focusing on two-handed manipulation, which can be tricky to get right.

This sample demonstrates six different types of locomotion:

  1. Point and Teleport — Use the thumbstick to point to where you want to go. An arc and indicator on the ground will show your destination and orientation after teleporting. Rotate the stick to change your target orientation. When the stick returns to neutral, you will be teleported to the destination.

  2. Point and Teleport (with Third-Person Avatar) — Identical to Point and Teleport, except a Third-Person Avatar will walk to the destination to show your teleport destination. This can be useful if you want to force the player to account for world geometry or travel time, while still allowing the comfort of teleportation.

  3. Stepped Translation and Rotation — Move forward and backwards at fixed increments with the left thumbstick and turn right and left in 35° intervals with the right thumbstick.

  4. Grab and Drag — Hold down the action buttons or triggers and move the controllers over the ground to “drag” yourself in a direction. This can also be adapted to handle vertical climbing.

  5. Arm Swinging — Hold down the action buttons or triggers and swing your arms to move forward in the direction the controllers are pointing.

  6. Dual-Stick Walking — The left stick controls translation and the right stick controls rotation like in a standard first-person game. This type of movement can be uncomfortable in VR, so it’s recommended that you only try it for short periods of time until you’re accustomed to it.

Mirrors and Portals

Mirrors and portals are a popular feature in VR experiences, but both can result in poor app performance if not executed correctly. This sample shows two ways to create mirrors and portals in your game.

Shadows (Baked/Dynamic)

Shadows are especially important in VR to showcase depth and realism, but shadows can start to consume your rendering budget as your world expands to include more objects. These samples show the performance effects of both Baked and Dynamic shadows in your game.


Creating clear and legible text in VR requires careful attention to how you handle texture filtering. This sample demonstrates how different filtering modes affect the rendering of rasterized text. It is primarily an interactive version of this developer blog article.

Color Grading

Color grading is a technique that lets you transform a scene from one set of colors to another, allowing you to simulate different lighting conditions or even moods. Normally, this is done as a post-process effect, but that can be prohibitively expensive on the tile-based GPUs used by mobile hardware. This sample shows an alternative method that does not incur the penalties of the post-processing approach (requires UE4.24).

Platform Permissions

If you’re used to developing for game consoles, you may be unfamiliar with Android mobile game development. As a result, you might not know how to request hardware permissions required by the platform. While requesting hardware permissions from the platform is common for many applications, it can be difficult to accomplish if you don't know the right buttons to push. This sample shows you how to find those buttons.

Downloadable Content (DLC)

As you’re developing your game or after you publish, you might want to add additional content to that game rather than publishing a new app to the store. Oculus enables that through downloadable content (DLC). This sample shows you how to quickly set up DLC for your game. For more information, check out this article on DLC and this article on Cloud Storage. Note that in order to create an app in the dev portal you'll have to have passed concept review first!

Let us know in the comments what other features and functionality you’d like to see highlighted in our blog or code repository. Looking forward to seeing what you build with these essentials!