Godot Version
4.4.1
Question
In multiplayer, the server-side MultiplayerSynchronizer cannot sync to clients, but clients can sync to the server and to other clients.
demo:GitHub - jinruozai/multiplayer_demo
https://imgur.com/a/hziEdG1
I created a global script called “lobby” to handle create_server, join_server, and start_game (using change_scene_to_file).
In the game scene, I did not use MultiplayerSpawner. Instead, I add all players from the lobby by iterating over multiplayer.get_peers().
Each player is assigned authority using set_multiplayer_authority.
Every player node has a MultiplayerSynchronizer attached to it, which is responsible for syncing position and rotation.
Players move using WASD or arrow keys, and pressing [J] calls an RPC function to change color and create a small cube.
I tested with three windows. When the server moves, its position and rotation are not synced to the clients. However, when a client moves, the movement syncs perfectly to the server and other clients. RPC function calls from the server work fine—pressing [J] successfully sends the action to other clients.
Previously, when both the lobby and the game scene were in the same scene, everything worked fine. Later, I refactored the lobby into a global script and switched scenes using change_scene_to_file, and then this issue appeared. I suspect the problem might be related to this change, but I’m not sure.
Can anyone help me figure out how to solve this? My current workaround is to sync position and rotation using RPC functions, but this doesn’t feel ideal. Any help would be greatly appreciated!
You should consider using a multiplayer spawner and only have the server add players. Changing the add_player a bit to a custom spawn function of the multiplayer spawner.
1 Like
Well, I have tried using the multiplayer spawner, and it works pretty well when everyone is in the same scene. However, after switching scenes with change_scene_to_file, the synchronization of the spawner often doesn’t behave as expected. So I removed the multiplayer spawner to minimize interference.
Additionally, this approach can also reduce some network communication, because once all players are connected in the lobby room, each client already knows about all the players. There’s no need to use the spawner to synchronize their creation over the network.
As for MultiplayerSynchronizer, it should only be related to the peers themselves, and not whether those peers were created by the multiplayer spawner, right? I want to first solve the MultiplayerSynchronizer issue when switching scenes, and then decide whether to use the multiplayer spawner for spawning based on future needs.
Not exactly. The spawner and syncer work together. If a syncher sends a packet before its remote counterpart exists it will fail and not be able to recover. The spawner will guard from this scenario until it has received a spawn packet and then will allow syncher packets to flow properly.
By letting each peer create their own nodes on the fly, opens you up for race conditions. If you still want to go this route i would advise writing your own behaviors using RPCs.
A good target is a 256kb stream so if your spawner is below that i wouldnt worry about it.
1 Like
I would also advise against change root scene in the start rpc, for the same reason of introducing race conditions.
1 Like
So, the problem I’m having right now is indeed caused by change_scene_to_file, isn’t it?
Thank you very much for your patient answers. I will carefully consider your suggestions. Thank you.