Inside my Scene I have a Barrel object that holds all the spawners for my worlds:
Then DevWorld will be spawned as a node using a custom spawn function that is called inside the DevWorldSpawner Node when a Client enters the world.
If the World is not active it will be activated. Every World will have the Public Visibility defaulted to “OFF” (Checkbox unchecked in the Synchronizer)
Inside that spawned World I have a PlayerShipSpawner Node that again uses a custom Spawn function to spawn the Player Ship:
When setting the Public Visibility off for the WorldSynchronizer like so:
Now on the server everything runs fine, also on Client 1 but when I enter the world with Client 2 I get the errors from above only on Client 2. Also Client 2 doesn’t spawn the PlayerShip but the Server aswell as Client 1 are spawning the PlayerShip.
A lookup on google:
I found a similar issue over on Github that has a similiar error regarding the Synchronizer and the cached object not being found on peer 1:
Question:
Is there a way to bypass that error or is this a known issue? And most importantly is there a way to get this to work?
It looks like it’s getting a command to spawn a player before the level is loaded. You could refactor the nested spawn outside the level, which, the level, may or may not need some time to load before a player could spawn.
Also because you have three processes. It could be the OS contributing to the server falling to the background and being demoted in CPU priority.
I will try to give as much details as possible so my apologies for the text wall:
Weird is that if I set the checkbox “Public Visibility” to true then both clients are being spawned in their according Spawner but then both Worlds are active on both clients.
I tested this with an RPC call from the client to the server when for the client the world has been spawned using the Spawned Event inside of the MultiplayerSpawner. The server sends the new visibility to the client. Then the client sends a rpc over to the server telling the server that the world has been spawned on the client machine. The server then again tells itself to perform the spawn of the player but according to the error output the message stays the same. It still can’t find the spawner to spawn the player ship.
Therefore, I’m not quite sure if the cpu priority has something to do with that. But I also can’t really tell because I have no idea what Godot is performing under the hood
Also tested it with the client waiting for a child to enter the spawner with ChildEnteredTree but with the same results.
What confuses me even more is that I have set up a Enemies spawner the exact same way inside the world and the enemies are getting spawned without an error, both on client and server. Worth noting is that I’ve built that said enemyspawner before building that multi world system. But I left the enemy spawner untouched and it’s being loaded upon the world activation. Also the movements of the enemies are both in-sync. If I then try to add another test spawner (and build it the same way as the enemy spawner), I get the error that the newly created spawner can not be found, eventhough there is nothing more happening than the enemy spawner that I already had before.
As mentioned this only occurs if I disable the visibility for both worlds and then selectively activating them for the peers, but when leaving the checkbox on by default, it does seem to work. Meaning both worlds are already loaded and also being displayed on both clients. Eventhough the goal is to only display one world at a time
I found out why my enemies are spawning without an error!
It’s because I am not setting a MultiplayerAuthority Peer Number on the enemies so the Authority will always be the server Peer 1. And with that no errors appear.
Other than in my PlayerShipSpawner I am setting the MultiplayerAuthority of my spawned PlayerShip. If I comment out the SetMultiplayerAuthority Method in my custom spawn function of the PlayerShip the errors disappear and all connected clients are spawning their ships accordingly in the correct world without any errors. I tried to post set the multiplayer authority via rpc both on client and server but then the errors re-appear
Finally found what the problem was:
The problem was because SetMultiplayerAuthority was setting the authority recursive and also for the synchronizer that was controlling the visibility. When only setting the authority on the parent object for the client but leaving the authority of the Synchronizer on the server the behaviour was as expected and the server was still able to control the visibility for the spawned object.