Table of Contents

Class XRServer

Namespace
Godot
Assembly
GodotSharp.dll

The AR/VR server is the heart of our Advanced and Virtual Reality solution and handles all the processing.

public static class XRServer
Inheritance
XRServer
Inherited Members

Properties

PrimaryInterface

The primary XRInterface currently bound to the XRServer.

public static XRInterface PrimaryInterface { get; set; }

Property Value

XRInterface

Singleton

public static XRServerInstance Singleton { get; }

Property Value

XRServerInstance

WorldOrigin

The current origin of our tracking space in the virtual world. This is used by the renderer to properly position the camera with new tracking data.

Note: This property is managed by the current XROrigin3D node. It is exposed for access from GDExtensions.

public static Transform3D WorldOrigin { get; set; }

Property Value

Transform3D

WorldScale

The scale of the game world compared to the real world. By default, most AR/VR platforms assume that 1 game unit corresponds to 1 real world meter.

public static double WorldScale { get; set; }

Property Value

double

Methods

AddInterface(XRInterface)

Registers an XRInterface object.

public static void AddInterface(XRInterface @interface)

Parameters

interface XRInterface

AddTracker(XRPositionalTracker)

Registers a new XRPositionalTracker that tracks a spatial location in real space.

public static void AddTracker(XRPositionalTracker tracker)

Parameters

tracker XRPositionalTracker

CenterOnHmd(RotationMode, bool)

This is an important function to understand correctly. AR and VR platforms all handle positioning slightly differently.

For platforms that do not offer spatial tracking, our origin point (0, 0, 0) is the location of our HMD, but you have little control over the direction the player is facing in the real world.

For platforms that do offer spatial tracking, our origin point depends very much on the system. For OpenVR, our origin point is usually the center of the tracking space, on the ground. For other platforms, it's often the location of the tracking camera.

This method allows you to center your tracker on the location of the HMD. It will take the current location of the HMD and use that to adjust all your tracking data; in essence, realigning the real world to your player's current position in the game world.

For this method to produce usable results, tracking information must be available. This often takes a few frames after starting your game.

You should call this method after a few seconds have passed. For example, when the user requests a realignment of the display holding a designated button on a controller for a short period of time, or when implementing a teleport mechanism.

public static void CenterOnHmd(XRServer.RotationMode rotationMode, bool keepHeight)

Parameters

rotationMode XRServer.RotationMode
keepHeight bool

FindInterface(string)

Finds an interface by its name. For example, if your project uses capabilities of an AR/VR platform, you can find the interface for that platform by name and initialize it.

public static XRInterface FindInterface(string name)

Parameters

name string

Returns

XRInterface

GetHmdTransform()

Returns the primary interface's transformation.

public static Transform3D GetHmdTransform()

Returns

Transform3D

GetInterface(int)

Returns the interface registered at the given idx index in the list of interfaces.

public static XRInterface GetInterface(int idx)

Parameters

idx int

Returns

XRInterface

GetInterfaceCount()

Returns the number of interfaces currently registered with the AR/VR server. If your project supports multiple AR/VR platforms, you can look through the available interface, and either present the user with a selection or simply try to initialize each interface and use the first one that returns true.

public static int GetInterfaceCount()

Returns

int

GetInterfaces()

Returns a list of available interfaces the ID and name of each interface.

public static Array<Dictionary> GetInterfaces()

Returns

Array<Dictionary>

GetReferenceFrame()

Returns the reference frame transform. Mostly used internally and exposed for GDExtension build interfaces.

public static Transform3D GetReferenceFrame()

Returns

Transform3D

GetTracker(StringName)

Returns the positional tracker with the given trackerName.

public static XRPositionalTracker GetTracker(StringName trackerName)

Parameters

trackerName StringName

Returns

XRPositionalTracker

GetTrackers(int)

Returns a dictionary of trackers for trackerTypes.

public static Dictionary GetTrackers(int trackerTypes)

Parameters

trackerTypes int

Returns

Dictionary

RemoveInterface(XRInterface)

Removes this interface.

public static void RemoveInterface(XRInterface @interface)

Parameters

interface XRInterface

RemoveTracker(XRPositionalTracker)

Removes this positional tracker.

public static void RemoveTracker(XRPositionalTracker tracker)

Parameters

tracker XRPositionalTracker

Events

InterfaceAdded

Emitted when a new interface has been added.

public static event XRServer.InterfaceAddedEventHandler InterfaceAdded

Event Type

XRServer.InterfaceAddedEventHandler

InterfaceRemoved

Emitted when an interface is removed.

public static event XRServer.InterfaceRemovedEventHandler InterfaceRemoved

Event Type

XRServer.InterfaceRemovedEventHandler

TrackerAdded

Emitted when a new tracker has been added. If you don't use a fixed number of controllers or if you're using XRAnchor3Ds for an AR solution, it is important to react to this signal to add the appropriate XRController3D or XRAnchor3D nodes related to this new tracker.

public static event XRServer.TrackerAddedEventHandler TrackerAdded

Event Type

XRServer.TrackerAddedEventHandler

TrackerRemoved

Emitted when a tracker is removed. You should remove any XRController3D or XRAnchor3D points if applicable. This is not mandatory, the nodes simply become inactive and will be made active again when a new tracker becomes available (i.e. a new controller is switched on that takes the place of the previous one).

public static event XRServer.TrackerRemovedEventHandler TrackerRemoved

Event Type

XRServer.TrackerRemovedEventHandler

TrackerUpdated

Emitted when an existing tracker has been updated. This can happen if the user switches controllers.

public static event XRServer.TrackerUpdatedEventHandler TrackerUpdated

Event Type

XRServer.TrackerUpdatedEventHandler