Creating an Application Using the Template

Getting Started#

UNIGINE has a ready-to-use configurable C++ VR template containing a sandbox-style scene with a set of interactive objects and components that can be manipulated using VR controllers. The template provides reusable core VR interaction components, input support for VR controllers, and default scene content for interaction and testing purposes.

The world has its settings optimized for best performance in VR.

The template is created using the Component System - components attached to objects determine their functionality.

You can extend an object's functionality simply by assigning it more components. For example, the laser pointer object in the template has the following components attached:

  • ObjMovable - enables grabbing and throwing an object
  • ObjLaserPointer - enables casting a ray of light by the object

You can also implement custom components to extend functionality.

Key features:

Interactive objects:

  • Movable and grabbable objects
  • Object rotation (handles, levers, valves)
  • Switches and buttons
  • Rope interaction
  • Sockets and plugs
  • Firearm interaction (pistol)
  • Laser pointer

Player systems:

  • Teleportation and free movement
  • Moving platforms and elevators
  • Inventory system
  • GUI menus (attached to the head and to the hand)
  • Interaction with GUI elements via controllers and hand tracking

Let's create a project based on the C++ VR Template.

  1. Open SDK Browser and go to the Templates tab. Find the VR C++ template and click Create Project.

    VR C++ Template

  2. Choose a name for your project (e.g. MyVRProject), its location, the SDK version, and precision. Then click Create New Project.

    Create New Project

  3. Once the project is created, it will appear on the My Projects tab. Open it in UnigineEditor to explore the scene.

    Open Editor

  4. To open the project in an IDE, select it on the My Projects tab and click Open Code IDE.

    Open Code IDE

Structure Overview#

Now, let's learn a bit more about the template structure. All components that implement the basic VR functionality are assigned to the corresponding nodes organized in the hierarchy with the vr_layer root node (see the picture below):

VR Template Structure (C++)

The structure of the vr_layer root node. The components attached to these nodes implement the core VR functionality: the player, controllers, menus, and inventory. Take a look at the other layers as well - they contain the environment and interactive objects that make up the demo scene.

The project contains a number of classes implementing the VR functionality. Here is a brief overview.

VRInteractable#

This is a base class (interface) for all objects that you can interact with. It defines a basic set of interactions: grabIt, holdIt, useIt, throwIt. You can add your own type of interaction here.

The following component classes implement VRInteractable:

# ObjMovableGrabbing, holding and throwing objects (a ball, a pistol, whatever you can take, carry and drop).
# ObjHandleObjects that can be turned or moved while being held (various handles, levers, valves, etc.).
# ObjSwitchObjects that can be switched by grabbing (all sorts of buttons and on-off switches, including rotary ones).
# ObjLaserPointer Casting a laser ray by the object. The laser pointer node has both ObjMovable and ObjLaserPointer components attached.

VRPlayer and VRPlayerSpawner#

VRPlayer is a base class for all players. It contains declaration of baseline controls, common basic player operations, and event management.

VRPlayerSpawner detects whether a VR headset is connected at startup. If yes, it spawns the VRPlayerVR (the VR player with HMD and controller tracking). Otherwise, it spawns the VRPlayerPC (a desktop player with keyboard + mouse control for VR emulation).

The VR player uses the VRPlayerMotor for physical movement (collisions, slopes, stepping on stairs). Input is handled by VRController and its subclasses:

  • VRHandController - maps physical controller buttons to abstract actions (GRAB, USE, TELEPORT, MENU, INVENTORY). This is where button remapping is done.
  • VRHandTracking - maps hand gestures to the same actions (requires OpenXR or Varjo + Ultraleap).

MenuBaseUI#

This is a base class for all graphic user interfaces (GUI).

The following component classes are inherited from MenuBaseUI:

Notice
These components can be attached to GUI objects only.
# HandMenuSampleGui This component implements initialization of widgets for the menu that is attached to a controller.
# MixedRealityMenuGui This component implements initialization of widgets for the menu that is attached to the HMD.
Best Practice

The template includes many more components than covered here. For a complete reference, see the VR Template Classes and Components article.

To quickly find which nodes use a specific component, right-click it in the Properties window and select Show World Nodes Using This One.

Show World Nodes Using This One

Setting Up a Device and Running#

Make sure you have installed your VR headset according to its manufacturer's instructions and that the VR runtime (SteamVR, Oculus, or the headset's native runtime) is running.

The VR Template supports any VR device that exposes input and tracking through a supported runtime backend (OpenXR, OpenVR, or Varjo). By default, VR is not initialized. To enable it, set the Stereo 3D option to the value that corresponds to your HMD (OpenXR, OpenVR, or Varjo) in the Global Options tab of the SDK Browser and click Apply.

Stereo 3D Setting

So, we're ready to see the template in action, let's build our application for the first time.

Don't forget to set the appropriate platform and configuration settings for the project before compiling your code in Visual Studio.

Build your application in Visual Studio (Build -> Build Solution) and launch it by selecting the project on the My Projects tab of the UNIGINE SDK Browser and clicking Run.

Before running your application via the UNIGINE SDK Browser make sure that appropriate Customize Run Options (Debug version in our case) are selected, by clicking an ellipsis under the Run button.

As the application starts, learn about basic mechanics, grab and throw objects, try to teleport and interact with objects in the scene.

The information on this page is valid for UNIGINE 2.22 SDK.

Last update: 2026-09-11 03:51:51