Table of Contents

Class XRInterface

Namespace
Godot
Assembly
GodotSharp.dll

This class needs to be implemented to make an AR or VR platform available to Godot and these should be implemented as C++ modules or GDExtension modules. Part of the interface is exposed to GDScript so you can detect, enable and configure an AR or VR platform.

Interfaces should be written in such a way that simply enabling them will give us a working setup. You can query the available interfaces through XRServer.

public class XRInterface : RefCounted, IDisposable
Inheritance
XRInterface
Implements
Derived
Inherited Members

Properties

ArIsAnchorDetectionEnabled

On an AR interface, true if anchor detection is enabled.

public bool ArIsAnchorDetectionEnabled { get; set; }

Property Value

bool

EnvironmentBlendMode

Specify how XR should blend in the environment. This is specific to certain AR and passthrough devices where camera images are blended in by the XR compositor.

public XRInterface.EnvironmentBlendModeEnum EnvironmentBlendMode { get; set; }

Property Value

XRInterface.EnvironmentBlendModeEnum

InterfaceIsPrimary

true if this is the primary interface.

public bool InterfaceIsPrimary { get; set; }

Property Value

bool

XRPlayAreaMode

The play area mode for this interface.

public XRInterface.PlayAreaMode XRPlayAreaMode { get; set; }

Property Value

XRInterface.PlayAreaMode

Methods

GetCameraFeedId()

If this is an AR interface that requires displaying a camera feed as the background, this method returns the feed ID in the CameraServer for this interface.

public int GetCameraFeedId()

Returns

int

GetCapabilities()

Returns a combination of XRInterface.Capabilities flags providing information about the capabilities of this interface.

public uint GetCapabilities()

Returns

uint

GetName()

Returns the name of this interface (OpenXR, OpenVR, OpenHMD, ARKit, etc).

public StringName GetName()

Returns

StringName

GetPlayArea()

Returns an array of vectors that denotes the physical play area mapped to the virtual space around the XROrigin3D point. The points form a convex polygon that can be used to react to or visualize the play area. This returns an empty array if this feature is not supported or if the information is not yet available.

public Vector3[] GetPlayArea()

Returns

Vector3[]

GetProjectionForView(uint, double, double, double)

Returns the projection matrix for a view/eye.

public Projection GetProjectionForView(uint view, double aspect, double near, double far)

Parameters

view uint
aspect double
near double
far double

Returns

Projection

GetRenderTargetSize()

Returns the resolution at which we should render our intermediate results before things like lens distortion are applied by the VR platform.

public Vector2 GetRenderTargetSize()

Returns

Vector2

GetSupportedEnvironmentBlendModes()

Returns the an array of supported environment blend modes, see XRInterface.EnvironmentBlendModeEnum.

public Array GetSupportedEnvironmentBlendModes()

Returns

Array

GetSystemInfo()

Returns a Dictionary with extra system info. Interfaces are expected to return XRRuntimeName and XRRuntimeVersion providing info about the used XR runtime. Additional entries may be provided specific to an interface.

Note:This information may only be available after Initialize() was successfully called.

public Dictionary GetSystemInfo()

Returns

Dictionary

GetTrackingStatus()

If supported, returns the status of our tracking. This will allow you to provide feedback to the user whether there are issues with positional tracking.

public XRInterface.TrackingStatus GetTrackingStatus()

Returns

XRInterface.TrackingStatus

GetTransformForView(uint, Transform3D)

Returns the transform for a view/eye.

view is the view/eye index.

camTransform is the transform that maps device coordinates to scene coordinates, typically the GlobalTransform of the current XROrigin3D.

public Transform3D GetTransformForView(uint view, Transform3D camTransform)

Parameters

view uint
camTransform Transform3D

Returns

Transform3D

GetViewCount()

Returns the number of views that need to be rendered for this device. 1 for Monoscopic, 2 for Stereoscopic.

public uint GetViewCount()

Returns

uint

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

Initialize()

Call this to initialize this interface. The first interface that is initialized is identified as the primary interface and it will be used for rendering output.

After initializing the interface you want to use you then need to enable the AR/VR mode of a viewport and rendering should commence.

Note: You must enable the XR mode on the main viewport for any device that uses the main output of Godot, such as for mobile VR.

If you do this for a platform that handles its own output (such as OpenVR) Godot will show just one eye without distortion on screen. Alternatively, you can add a separate viewport node to your scene and enable AR/VR on that viewport. It will be used to output to the HMD, leaving you free to do anything you like in the main window, such as using a separate camera as a spectator camera or rendering something completely different.

While currently not used, you can activate additional interfaces. You may wish to do this if you want to track controllers from other platforms. However, at this point in time only one interface can render to an HMD.

public bool Initialize()

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

IsInitialized()

Is true if this interface has been initialized.

public bool IsInitialized()

Returns

bool

IsPassthroughEnabled()

Is true if passthrough is enabled.

public bool IsPassthroughEnabled()

Returns

bool

IsPassthroughSupported()

Is true if this interface supports passthrough.

public bool IsPassthroughSupported()

Returns

bool

StartPassthrough()

Starts passthrough, will return false if passthrough couldn't be started.

Note: The viewport used for XR must have a transparent background, otherwise passthrough may not properly render.

public bool StartPassthrough()

Returns

bool

StopPassthrough()

Stops passthrough.

public void StopPassthrough()

SupportsPlayAreaMode(PlayAreaMode)

Call this to find out if a given play area mode is supported by this interface.

public bool SupportsPlayAreaMode(XRInterface.PlayAreaMode mode)

Parameters

mode XRInterface.PlayAreaMode

Returns

bool

TriggerHapticPulse(string, StringName, double, double, double, double)

Triggers a haptic pulse on a device associated with this interface.

actionName is the name of the action for this pulse.

trackerName is optional and can be used to direct the pulse to a specific device provided that device is bound to this haptic.

public void TriggerHapticPulse(string actionName, StringName trackerName, double frequency, double amplitude, double durationSec, double delaySec)

Parameters

actionName string
trackerName StringName
frequency double
amplitude double
durationSec double
delaySec double

Uninitialize()

Turns the interface off.

public void Uninitialize()

Events

PlayAreaChanged

Emitted when the play area is changed. This can be a result of the player resetting the boundary or entering a new play area, the player changing the play area mode, the world scale changing or the player resetting their headset orientation.

public event XRInterface.PlayAreaChangedEventHandler PlayAreaChanged

Event Type

XRInterface.PlayAreaChangedEventHandler