Handling multiple scenes in networking multiplayer games

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By qazwsx
:warning: Old Version Published before Godot 3 was released.

Is there any good pattern to handle multiple scenes in multiplayer networking game? I have written the networking game client-server. I have working game but everything is in one scene. I want to divide the game into multiple sub-scenes as per below (simplified):

  • Menu (start server/ join the game)
  • Room (players join the game - connects to server)
  • Game (players play through the network)

The transition from Menu to Room will probably work with no issues. But how should be solved the switch from Room to Game? I think the scene switch will remove all the children of Room scene so all connections will be lost. I need to have these connections in Game scene. Any static objects or something like that?

I want to add that I am aware of Singletons. I am asking about good practice or good pattern to handle such case.

Way I do it is just using a state machine and send a small 1 byte packet to the server to sync game states. This way, since Godot has no error handling, the possibilities for crashing is greatly reduced (i use a global gg.GAMESTATE) object

wombatTurkey | 2016-08-17 16:55

:bust_in_silhouette: Reply From: Tybobobo

With the newer high level networking API, it is much easier to achieve what you want.
I had trouble with the same, although more with handling in-session joining.

In this demo, you can find out how both lobby and in-game scene transition can work.

Hope you find it useful.