Godot Version
v4.3-dev5_mono_linux_x86_64
Question
I am trying to follow along with the Snopek Rollback Netcode tutorial series. The videos are excellent- unfortunately the tutorials have not been updated to Godot 4 and probably never will be. (The add-on itself has been.) So I’m going through and fixing the errors one at a time as they show up, looking up the new Godot 4 way to do each thing that doesn’t work as written. I am only halfway through the second video and I’m already stuck.
The server button gives this error when clicked:
main.gd:17 @ _on_server_button_pressed(): Couldn't create an ENet host.
That’s not very helpful, but if I expand it, the next message on the error stack is:
<C++ Error> Parameter "host" is null.
What? ENetMultiplayerPeer.create_server does not take a host parameter. create_client does. I figured the C++ module must be getting it from somewhere else and it needs to be set before calling create_server.
So I added the line
peer.set_bind_ip( host_field.text )
Which as far as I could tell from the docs, is how you do that. That should have told it to listen on 127.0.0.1- what it says in the GUI HostField -when I create a server. Right? Nope. Same error.
Well, that’s it. I am out of ideas.
extends Node2D
@onready var connection_panel = $CanvasLayer/ConnectionPanel
@onready var host_field = $CanvasLayer/ConnectionPanel/GridContainer/HostField
@onready var port_field = $CanvasLayer/ConnectionPanel/GridContainer/PortField
@onready var message_label = $CanvasLayer/MessageLabel
func _ready() -> void:
multiplayer.peer_connected.connect(_on_network_peer_connected)
multiplayer.peer_disconnected.connect(_on_network_peer_disconnected)
multiplayer.server_disconnected.connect( _on_server_disconnected)
func _on_server_button_pressed() -> void:
var peer = ENetMultiplayerPeer.new()
peer.set_bind_ip( host_field.text )
peer.create_server( int(port_field.text), 1 )
multiplayer.set_multiplayer_peer(peer)
connection_panel.visible = false
message_label.text = "Listening..."
func _on_client_button_pressed() -> void:
var peer = ENetMultiplayerPeer.new()
peer.create_client( host_field.text, int(port_field.text) )
multiplayer.set_multiplayer_peer(peer)
connection_panel.visible = false
message_label.text = "Connecting..."
func _on_network_peer_connected(peer_id: int):
message_label.text = "Connected!"
func _on_network_peer_disconnected(peer_id: int):
message_label.text = "Disconnected."
func _on_server_disconnected(peer_id: int):
_on_network_peer_disconnected(1)