Godot Version
4.2.1.stable
Question
Hey there!
Hope you are all doing great!
I am currently trying to implement multiplayer for my 2d game and am following this tutorial: https://www.youtube.com/watch?v=V4a_J38XdHk&ab_channel=BatteryAcidDev
All works well until I try to set a player_id and the multiplayer authority on my MultiplayerSyncronizer.
I’ll skip the (I hope) not important code parts.
So basically I have a script that adds players to the game and creates a server:
func _add_player_to_game(id: int):
print("Player %s joined the game!" % id)
var player_to_add = multiplayer_scene.instantiate()
player_to_add.player_id = id
player_to_add.name = str(id)
_players_spawn_node.add_child(player_to_add, true)
I have a Player script that should set the player_id and authority like this:
@export var player_id := 1:
set(id):
player_id = id
%InputSynchronizer.set_multiplayer_authority(id)
And I get this error:
E 0:00:03:0886 on_replication_start: The MultiplayerSynchronizer at path "/root/World/Players/200348540/PlayerSynchronizer" is unable to process the pending spawn since it has no network ID. This might happen when changing the multiplayer authority during the "_ready" callback. Make sure to only change the authority of multiplayer synchronizers during "_enter_tree" or the "_spawn_custom" callback of their multiplayer spawner.
<C++ Error> Condition "pending_sync_net_ids.is_empty()" is true. Returning: ERR_INVALID_DATA
<C++ Source> modules/multiplayer/scene_replication_interface.cpp:247 @ on_replication_start()
I have a MultiplayerSpawner and a Node where he spawns them as well as the scenes set that the Spawner should create and it works fine for the host, but as soon as I try to join with the second player, the error above appears.
This is my MultiplayerPlayer setup.
It looks like it tries to set the player_id to 1 every time even tho I get a unique multipalyer ID.
I have no idea how to fix it and been struggling with this for the past 3 hours, does anyone of you maybe have an idea? I saw others struggling with this too but couldn’t find a solution yet.
Thank you very much!