Godot 3 to 4 rename

WebRTCPeerConnectionGDNative in Godot 4: it is WebRTCPeerConnectionExtension now

WebRTCPeerConnectionGDNative is WebRTCPeerConnectionExtension in Godot 4.7.2, but game code creates neither: it creates a WebRTCPeerConnection, and Godot returns the implementation a WebRTC extension registered. On desktop with no extension installed, Godot warns No default WebRTC extension configured. and returns a bare WebRTCPeerConnectionExtension, whose methods nothing implements.

What Godot prints

A Godot 3 script that creates the GDNative WebRTC peer connection directly.

repro.gd
extends Node

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

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

The fix

Game code creates a WebRTCPeerConnection and lets Godot pick the implementation. This run is on desktop with no WebRTC extension installed, so Godot warns once and hands back a bare WebRTCPeerConnectionExtension.

fix.gd
extends Node

func _ready() -> void:
	var peer := WebRTCPeerConnection.new()
	print(peer.get_class(), " is a WebRTCPeerConnectionExtension: ", peer is WebRTCPeerConnectionExtension)
Output, Godot 4.7.2
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

WARNING: No default WebRTC extension configured.
   at: create (modules/webrtc/webrtc_peer_connection.cpp:53)
   GDScript backtrace (most recent call first):
       [0] _ready (res://answers/webrtcpeerconnectiongdnative-in-godot-4/fix.gd:4)
WebRTCPeerConnectionExtension is a WebRTCPeerConnectionExtension: true

Why it happens

GDScript's analyzer resolves every identifier when the script loads. WebRTCPeerConnectionGDNative 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 the new name from Godot's 3 to 4 rename table: Did you mean to use "WebRTCPeerConnectionExtension"?

WebRTCPeerConnection.new() goes through WebRTCPeerConnection::create(). In a web export it returns the browser's WebRTC implementation. Everywhere else it instantiates the class set with WebRTCPeerConnection.set_default_extension(), which has to extend WebRTCPeerConnectionExtension.

With no default set, create() prints the warning once and returns a plain WebRTCPeerConnectionExtension, which is what the fix's run got. Its methods (initialize, create_offer, poll, get_connection_state and the rest) are bound for a GDExtension to implement, so on the bare class they have no body to run.

The table renames Godot 3's other GDNative networking classes the same way: WebRTCDataChannelGDNative, PacketPeerGDNative, StreamPeerGDNative and MultiplayerPeerGDNative each become the class of the same name ending in Extension.

Sources

Run on Godot 4.7.2, .

Related