Photon Multiplayer (RLGL) - Guide

[SMPL-RLGL-02]

This document and the sample project allow game makers to understand and apply the benefits of both Beamable and Photon Fusion to create a realtime multiplayer game.

Photon Fusion Overview

500500

Fusion is a new high performance state synchronization networking library for Unity. With a single API, it supports many network architectures such as dedicated server, client hosted and shared/distributed authority.

This sample project showcases how Beamable and Photon can work together to provide a sophisticated networking solution. In general, Beamable handles the social and economy features, while Photon handles the gameplay. The Matchmaking feature bridges the gap between these two technologies.

To learn more about Photon Fusion, read more on the official documentation.

Project Setup (Required Steps)

Beamable Setup

StepDetail
1. Download the sample project from GitHubMultiplayer RLGL Sample Project
2. Open in Unity EditorUnity version 2020.3.22
3. Open the Beamable ToolboxBeamable Toolbox
4. Sign-In / Register To BeamableSee Installing Beamable for more info
5. Open the Login SceneAssets/_Game/Scenes/Login.unity

Photon Setup

1. Create a Photon accountThis can be done on Photon's website.
2. Create a Photon Fusion appFusion Introduction
3. Copy and paste your Fusion App ID into the PhotonAppSettingsThis is located in the project, in Assets/Photon/Fusion/Resources/PhotonAppSettings.

After these steps are complete, the game is ready to test. Open the Login scene, then click Play in the editor. Once you're in the main menu, either click "Find Match", or do a standalone build of the game and run the build. Then run the Unity Editor. In both running games, choose "Find Match" to play against yourself.

Additional Project Setup (Optional)

The sample project includes additional features that are not required to run the game.

StepDetail
Setup Facebook Sign-InFacebook Sign-In - Overview.
Setup Google Sign-InGoogle Sign-In - Overview
Setup Steam Sign-InSteam Integration - Overview

Installing Photon Fusion

In the Red Light, Green Light sample project, the Photon Fusion SDK is already installed in the Unity project. However, installing the SDK into your own Unity project is simple. A full guide for installing the Photon Fusion SDK can be found here: Fusion 101 - Getting Started. The basic steps include:

• Create a PhotonEngine account
• Download and Install the Fusion SDK in your Unity project
• Configure your Unity project and connect it to your Photon App ID

You will need a unique Photon App ID for each of your Beamable games.

Rules of the Game

The game starts with the players in a waiting area, with a wall blocking them from proceeding until all players are ready. After all players ready up, the wall will disappear and the players can proceed.

Throughout the match, the ball of light at the end will change colors from green, to yellow, then red (like a traffic light). While the light is green, players are free to move around. While the light is red, the players cannot move if they are able to be seen by the ball of light. Doing so will result in the players being zapped by the light.

Players can pick up various weapons on the field and deal damage to other players. Unarmed players can shove other players, potentially causing them to be seen moving while the light is red and getting zapped.

The goal of the game is to make it all the way to the other side of the map without being seen moving by the red light, or being killed by another player. After the round is over, the player will earn currency that can be used to purchase items in the store, and they will earn a spot on the leaderboard based on their performance.

Player Experience Flowchart

Here is the high level execution flow of user input and system interactions.

20422042

The main link here is the connection between Beamable's Matchmaking and Photon's NetworkRunner. StartMatchmaking will initiate a search for other players to join into a match. Information about that search is stored in the MatchmakingHandle, provided by the MatchmakingService. When the search is complete, the ID of the match ticket can be retrieved. The following code is paraphrased from MatchmakingHandler.cs in the sample:

public async void StartMatchmaking()
{
    var handle = await _beamableAPI.Experimental.MatchmakingService.StartMatchmaking(gameTypeRef, UpdateHandler, ReadyHandler, TimeoutHandler);
}

private void ReadyHandler(MatchmakingHandle handle)
{
    //Store this match ID somewhere, since we will need it later.
    //In the sample project, it is stored in a ScriptableObject.
    var matchId = handle.Match.matchId;
}

Once we have the match ID, we can use it as the ID of the Photon room to join. This way, we can ensure all the other players that have been matched together will join the same room at the same time. Here is a snippet from FusionLauncher.cs:

//_runner is a NetworkRunner, a Photon class representing a simulation.
await _runner.StartGame(new StartGameArgs()
{
    GameMode = mode, 
    SessionName = matchId,
    SceneObjectProvider = sceneLoader,
    PlayerCount = playerCount
});

Additional Steps

Follow these steps to get started:

🚧

Note

These steps are already complete in the sample project. The instructions here explain the process for setting up your own project with these same tools.

Setup Project

Here are instructions to setup the Game Type content.

992992

Note that since there are no "team" divisions, all the players are placed on the same team. Additionally, the maximum player count (200) is derived from Photon Fusion's maximum supported players.

StepDetail
1. Install the Beamable SDK and Register/Login• See Installing Beamable for more info.
2. Open the Content Manager Window• Unity → Window → Beamable → Open Content Manager
3. Create the "GameType" content




• Select the content type in the list
• Press the "Create" button
• Populate the content name
4. Configure "GameType" content


• Populate the Max Players and Teams

Note: The other fields are optional and may be needed for advanced use cases

5. Configure "GameType" content (continued)


• Populate the String Rules pictured here.

These are necessary in order for the Red Light, Green Light game to function properly. In your own implementation, these may not be necessary.

6. Save the Unity Project• Unity → File → Save Project


Best Practice: If you are working on a team, commit to version control in this step
7. Publish the content• Press the "Publish" button in the Content Manager Window