Need Help With Multiplayer Error Resolving ("!nid" is true) and ("!p_buffer || p_size < 1" is true)

Godot Version

4.2.2

Question

How do I resolve E 0:00:05:0894 _make_spawn_packet: Condition “!nid” is true. and E 0:00:05:0894 _send_raw: Condition “!p_buffer || p_size < 1” is true. errors?

I’m trying to make a multiplayer system similar to Minecraft’s. For now it’s very simple: you can move around, host the world, and when someone joins it, the location of all players is synced. What I don’t understand, is that everything works perfectly, but I still get these errors. Here is my code for the world node:

extends Node3D

@export var player : PackedScene = preload(“res://assets/scenes/player/player.tscn”)
@onready var player_container = $Worlds/Default/Entities/Players
@onready var multiplayer_spawner = $MultiplayerSpawner

func _ready():
multiplayer.peer_connected.connect(on_peer_connected)
multiplayer.peer_disconnected.connect(on_peer_disconnected)

func _on_host_pressed():
# Host a server
var peer = ENetMultiplayerPeer.new()
peer.create_server(135)
multiplayer.multiplayer_peer = peer

# Deleting the player created in the _on_create_world function removes errors, but doesn't allow the hoster to play the game
#rpc('_del_player', 1)

# Adding another player, creates a new player but with the name of 2, still not allowing the hoster to play the game
#on_peer_connected()

func _on_join_pressed():
#Join server
var peer = ENetMultiplayerPeer.new()
peer.create_client(“localhost”, 135)
multiplayer.multiplayer_peer = peer

func _on_create_world():
# Add single player with no server
add_player(1)

func on_peer_connected(id : int = 1):
print(“Peer connected with ID:”, id)
add_player(id)

func on_peer_disconnected(id):
print(“Peer disconnected with ID:”, id)
rpc(‘_del_player’, id)

@rpc(“any_peer”, ‘call_remote’, ‘reliable’)
func add_player(id : int = 1):
var plr = player.instantiate()
plr.name = str(id)
player_container.call_deferred(‘add_child’, plr, true)

func exit_game(id):
on_peer_disconnected(id)

@rpc(‘any_peer’, ‘call_local’, ‘reliable’)
func _del_player(id):
player_container.get_node(str(id)).queue_free()

What is the sequence of events for host and client? I see some interesting buttons like create world.

Also many RPC’s, you can avoid RPC if you use a MultiplayerSpawner.

The game starts in a main menu screen. That main menu has 2 buttons: one to create a world and one to join a world. Pressing create world creates a new world instance as a child of the main menu. Creating a world doesn’t create a server. When the world is created there is a host button which then hosts the world for others to join.

I do use a MultiplayerSpawner, so this line shouldn’t exist (@rpc(“any_peer”, ‘call_remote’, ‘reliable’), I just forgot to remove it.

I think I’ve found the root of my problem. I’m creating a player instance BEFORE a server so the MultiplayerSpawner node doesn’t sync that particular player instance across clients. I can somewhat mitigate this by manually adding the host player when each client joins. This allows everything to run seemingly smoothly, but it would cause problems when trying to scale.

I’m a bit lost on how to sync a player that is created before a server. Anyone got any tips?

I was thinking this could be the issue.

I don’t have any tips atm.

Looking at the src again. The multiplayer_api ( refered to as multiplayer in code) defaults to a SceneMultiplayer instance and an offline packet_peer. When in offline the spawner will interact with a replicator interface internal to the SceneMultiplayer. There is nothing very destructive when changing the packet_peer to be online. And the replicator interface should start sending spawn commands when a peer connects. I think there could be a bug somewhere.

I’ll try to throw a debugger on it for the practice when I get a chance.

1 Like

I appreciate your help through all this. I think for now, I’m going to restructure my project’s functionality to avoid the bug altogether. On world creation, I’ll give the option to be either singleplayer or multiplayer, this way the world knows rather to start a server on startup or not. This will require the player to quit to the main menu and reload the world for it to be multiplayer, but I guess that’ll do for now.

I don’t want to make changes to the engine itself as that’s likely to become a headache later down the line.

I’ll wait for your debug, if you plan to continue, so we know rather to classify this as a bug or request singleplayer to multiplayer support for the MultiplayerSpawner/MultiplayerSynchronizer nodes. Otherwise, I’ll just mark your previous response as the solution.

Once again, thank you for your help.

I haven’t run the debug session yet, but from the preliminary setup I could not replicate the issue.

My spawner was watching a separate node. And I added items before multiplayer peer, after server before client join, and after client join. All three items spawned for client.

I think the issue could be that is the client spawns anything before joining there may be some issues.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.