Add Dedicated Game Server to Mirror Networking's Pong Example - Learn How to Host a Unity Multiplayer Game

In this video, we will cover every step on how to easily deploy a game server to host Mirror Networking's "Pong" multiplayer example for two players directly from Unity's editor using Edgegap.

Let’s get started

Part 1 - Setup

Starting from an all-new project from Unity’s HUB, select "Install Editor" and select the latest version available. Which was Unity 6.1 at the time of recording.

Create and start a new project.

Once the editor is open, head over to Unity's Asset Store and, making your sure are logged in, find the Mirror Networking project and select "Add to My Assets".

Your "Package Manager" should open automatically. If not, in the editor select "Window" from the top navigation bar then "Package Manager".

Once opened, select "Import to Project" to add Mirror Networking to your project. Click on "Install/Upgrade"

Then, Unity prompts you to import it. Select "Import" once again.

Congrats, Mirror is now in your project and should be visible from your "Assets" navigation menu on the bottom left of the editor.

To open the example, select "Mirror" then "Examples", then "Pong" and finally "Scenes". Open the "MirrorPong" scene.

In your "Game Scene" in Unity's editor, confirm the scene has been opened.

Part 2 - Create a Game Server & Host it on Edgegap

The next step is to deploy a game server to have players connect to the host and play online. Edgegap is a game server orchestration platform tailored for multiplayer games that helps you host your multiplayer easily.

First, create a free Edgegap account.

Head to "Edgegap.com" and select "Start for Free". Input your email and a password and opt in to our terms. You'll then instantly get a verification email. Click on "Confirm Your Email" to validate your account. Finally, input your organization's name and confirm.

This is Edgegap application's dashboard. We strongly recommend exploring it with the tour, but we'll skip it for this video.

Edgegap has automated the process of creating an app version using the Mirror Pong sample. While you can create a version manually, simply head over to our documentation and select the "Create a new app version for your application" link, which is also available in the description and comments.

The "Create an Application" prompt is now pre-filled. Select "Create an Application", then select the "Mirror Pong Unity" button which automatically fills the application's metadata.

Then, scroll down and select "Submit". The "Create a Port" prompt highlights the accurate port, namely 7777 and the protocol, in this case UDP. Scroll down and select "Submit".

With your application created, the next step is to create a deployment which is the game server players will connect to.

From the navigation menu, select "Deployments". Then, click on the "Create a Deployment" button.

Your latest application and its version are set by default, here our Mirror Pong example. Select the ideal region for you, in our case Americas, scroll down and click on "Deploy".

After a few seconds, the deployment of the game server changes its status from “Waiting” to "Ready".

Congratulations, you've deployed your first game server!

Click on the deployment to open its detail page, which highlights where the game server was deployed.

Please make sure to note the URL to which players must connect to, under the "Host" section. It is also important to note the External Port for testing.

Part 3 - Testing

To test multiplayer games, you need more than one player. To simulate this, you need the "Multiplayer Play Mode" package.

Return to Unity's Package Manager, select the "Unity Registry" tab and scroll down to find it. Or type "Multiplayer Play Mode". Install the package.

Once installed, return to your game scene. Then, from the top navigation bar, select "Window" and "Multiplayer Play Mode" to open the editor.

Under "Virtual Players" select the amount of players you need. In this tutorial, we'll have two. Select and save your selection.

The second to last step is to start the game scene in Unity.

Once loaded, both the game scene representing "Player 1" and the Multiplayer Play Mode window representing Player 2 should be functional.

We'll move each window to make things easier to see, but this is purely optional.

In both windows, replace "localhost" with the host's URL from the game server deployment. Simply return to the detail page and copy the URL and paste it.

Return to the detail page and now select the "External Port" and paste it in both Player 1 (Editor) and Player 2 (Multiplayer Play Mode).

In both players' windows, select "Client" to have each player connect to the game server.

As you can see, both players are connected to the game server, and the game is synchronized with each player's input.

If you have an error regarding input in the console, we recommend uninstalling the "Input System" from the Package Manager which will solve this issue.

Congratulations, you are now using Mirror Networking's transport to play multiplayer online using Edgegap's game server hosting platform.

Mirror's example is a great tool to learn networking.

The next step in your development journey will be to create a game server for your own Unity project.

Our game server tutorial for Unity is viewable on YouTube which is available on screen and highlights every step to get your game online and have players connect to it.

Edgegap also offers a matchmaker whose tutorial is also linked on this screen.