trying to start an ENet server

godot-4

Hi, I’m trying to create and run a server using this code

var server_port = 1610
var max_servers = 5
@onready var peer = ENetMultiplayerPeer.new()
# Called when the node enters the scene
func _ready():
	start_server()

# Function to start the server
func start_server():`Preformatted text`
	var result = peer.create_server(server_port, max_servers)
	if result != OK:
		print("Failed to create server on port - ", server_port, " ", result)
		return
	# Set the network peer for the multiplayer system
	multiplayer.multiplayer_peer = peer

Im getting the err

E 0:00:00:0837   Authenticate.gd:13 @ start_server(): Couldn't create an ENet host.
  <C++ Error>    Parameter "host" is null.
  <C++ Source>   modules/enet/enet_connection.cpp:318 @ _create()
  <Stack Trace>  Authenticate.gd:13 @ start_server()
                 Authenticate.gd:8 @ _ready()

I have another project that has the identical code (that proj has port 1609 insted of 1610), and it works so I’m stuck

Maybe try getting rid of @onready for the peer, enet object. It could be a race condition, and it should be fine to have it create the entire object on init instead of ready.