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.
extends Node
func _ready():
var peer = WebRTCPeerConnectionGDNative.new()
print(peer.get_connection_state())
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.
extends Node
func _ready() -> void:
var peer := WebRTCPeerConnection.new()
print(peer.get_class(), " is a WebRTCPeerConnectionExtension: ", peer is WebRTCPeerConnectionExtension)
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: trueWhy 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
- renames_map_3_to_4.cpp line 1657, WebRTCPeerConnectionGDNative to WebRTCPeerConnectionExtension
- gdscript_analyzer.cpp line 4687, the error with the rename hint
- webrtc_peer_connection.cpp lines 48 to 64, create() and the warning
- webrtc_peer_connection_extension.h, the methods an extension implements
- WebRTCPeerConnection.set_default_extension in the class reference
- renames_map_3_to_4.cpp lines 1544, 1559, 1605 and 1655, the other GDNative network classes
Run on Godot 4.7.2, .