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()