Godot 3 to 4 rename

ARVRInterfaceGDNative in Godot 4: there is no such class

Godot 4 has no ARVRInterfaceGDNative and no class to rename it to. The converter's table maps it to Node3D, so the editor's error suggests Node3D, but an XR interface is not a node: XR plugins inherit XRInterfaceExtension now, and game code finds an interface through XRServer.

What Godot prints

A Godot 3 script that creates an ARVRInterfaceGDNative, the base class XR plugins used through GDNative.

repro.gd
extends Node

func _ready():
	var xr = ARVRInterfaceGDNative.new()
	print(xr.get_name())
Output, Godot 4.7.2
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

SCRIPT ERROR: Parse Error: Identifier "ARVRInterfaceGDNative" not declared in the current scope. Did you mean to use "Node3D"?
   at: GDScript::reload (res://answers/arvrinterfacegdnative-in-godot-4/repro.gd:4)
ERROR: Failed to load script "res://answers/arvrinterfacegdnative-in-godot-4/repro.gd" with error "Parse error".
   at: load (modules/gdscript/gdscript_resource_format.cpp:46)

The fix

Godot 4 code reaches XR interfaces through XRServer. get_interfaces() returns one Dictionary per interface, with its id and name; find_interface() returns the interface itself.

fix.gd
extends Node

func _ready() -> void:
	for info in XRServer.get_interfaces():
		print(info["id"], ": ", info["name"])
	var openxr := XRServer.find_interface("OpenXR")
	print("OpenXR interface: ", openxr.get_class() if openxr else "not found")
Output, Godot 4.7.2
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

0: Native mobile
1: OpenXR
OpenXR interface: OpenXRInterface

Why it happens

In Godot 3.6, ARVRInterfaceGDNative was the GDNative wrapper for an ARVR interface: you instantiated it and set the GDNative library holding the interface.

GDScript's analyzer resolves every identifier when the script loads. ARVRInterfaceGDNative is not a class in Godot 4.7.2, so the script fails to parse and Godot does not load it. The editor build adds a name from Godot's 3 to 4 rename table, and this class's entry there is Node3D, so the error ends with Did you mean to use "Node3D"? Node3D is the base 3D scene node, not an XR interface.

An XR interface plugin for Godot 4 inherits XRInterfaceExtension, the base class the class reference names for XR interface extensions.

ARVRServer and ARVRInterface are XRServer and XRInterface. XRServer.get_interfaces() returns one Dictionary per interface with its id and name, so read info["name"]; find_interface() returns the XRInterface itself. In this headless run the list held Native mobile and OpenXR, and find_interface("OpenXR") returned an OpenXRInterface.

Sources

Run on Godot 4.7.2, .

Related