Test and Play

3 - 5 minutes read

At this point, you have set up the Player prefab, configured the Scene Spawner, and updated the LobbyScene to load the Game Scene. It's time to have some fun now. Let's build the game and test out what we have created so far.

Disable the Player GameObject in the Game Scene Hierarchy as we want the SceneSpawner to create the Players.

Custom Player Id

SWNetwork generates unique playerId for each game installation. This is for SocketWeaver to identify a client. If you call NetworkClient.Instance.CheckIn(), the generated playerId will be used to check the client into the SocketWeaver services. The first line in the black box is the generated playerId: a9d91dbd-64...

You can use custom player Id to override the generated playerId by calling NetworkClient.Instance.CheckIn(customPlayerId). This is useful if you use service like Google Firebase to manage user profiles. You can use it for development testing as well.

Build and Run

Select Build Settings... and make sure you have added the welcome scene and game scene to the game. The welcome scene should have index 0. The game scene should have index 1.

Select Build And Run to build the game.

In the Game Configuration window, select the resolution and Graphics quality you like and enable "Windowed". Click on the "Play!" button to start the game.

The game should launch to the LobbyScene. Enter "player1" as custom player Id and click the Register button. You should see the Play button replaces the Register button indicating that you have successfully checked in and are ready to join or create rooms. Click the Play button to join or create a room.

As there is no room on the lobby server for your game, the local player "player1" is the owner of the new room. The matchmaking logic of the LobbyScene automatically starts the room and connects to the room once it becomes ready. The game should load the game scene now.

Running another client in the Unity Editor

In the Unity Editor, load the LobbyScene and play. Enter "player2" as the custom player Id and click the Register button.

Notice the playerId in the NetworkClient is overridden by the custom playerId you entered.

Click the Play button, the "player2" client will try to join or create a room. It will find the room that "player1" created. Since the room has already started, "player2" will automatically connect to the game servers and load the game scene.

Move around in the scene and try to find "player1"!

Congratulations! You found "player1".

‚Äč