Mirror Networking Plugin - Automated Game Server Hosting - Unity Tutorial

In this video, we will cover how to set up Mirror Networking’s free and open source netcode in combination with Edgegap’s hosting within your project to deploy, and host, an automated game server directly from Unity’s editor. As to get your game online and playable, worldwide, in seconds.

Let’s get to it.

Chapter 2: Setup

Before using the plugin, there are three requirements to ensure everything works.

First, make sure you use the latest Mirror plugin. It can be downloaded directly from the Unity asset store. A direct link is in the description.

Once installed and imported Mirror from the store, access it by selecting “Window” from the top menu, then select “Package Manager.” Then, from the drop down select “My Assets” to find the Mirror plugin. For new users, we strongly recommend watching the amazing community tutorials to use Mirror to its full capabilities.

Second, within Unity, head over to Unity’s Hub to confirm you have installed the “Linux Dedicated Server Build Support” module in your project. If not, simply click on the package and install it.

The third and final prerequisite is to install and run Docker. It containerizes your game servers to help it deploy and run faster. If you haven’t yet, you can go watch our Docker installation video, or head over to Docket dot com and follow the installation procedure. It’s easy and takes just a few minutes. 

Now, let’s get started!

Chapter 3: Mirror Networking

Load up your project. In our case, we are using the tank sample project from Mirror Networking that is already setup for dedicated game servers.

To make sure it runs smoothly, select the “Network Manager” game object in the scene of the Mirror plugin and in the component inspector, confirm that all three configurations, namely “Don’t Destroy On Load”, “Run in Background” and “Auto Start Server Build” are enabled.

Additionally, if you have different scenes depending on whether the player is offline or online, you can drag and drop scenes from your assets to the appropriate “Scene Management” section. This ensures automatic transition between online, hosted servers to offline play.

Finally, note the “Network Address” should be currently set to “Local Host”. This will be swapped to the hosting address later after the Edgegap game server is deployed. Similarly, the “Transport Configuration” port value is likely set to a default, internal state such as 7777 which will have to be updated too.

Chapter 4: Edgegap Plugin

The Edgegap plugin should be included in the latest Mirror package. To use it, select the navigation bar’s “Edgegap” option, then select “Edgegap Hosting” which will open up the plugin’s window.

To function, you will have to generate a token.

To do so, you must create an Edgegap account. Click on the “Get a Token” button which will open up your browser.

Signing up is free and takes just a few seconds. First, select “Get Started” at the bottom, then from the login screen, input your email and a password and opt into 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. Automatically, a pop up with your unique OneClick Token appears. Simply copy it by clicking on the clipboard icon and paste it directly in the plugin’s text box.

Then, select verify which confirms the token is valid. The “Application Info” tab now opens automatically.

Should you already have an application on our platform, input its name in the text box and load it as an existing app. If not, which is the case in this tutorial, simply enter your project’s name. It must be in lowercase, with no spaces.

The “Create Application” button is now enabled. Select it. This opens the “Container Registry” and the “Deployment” tabs.

Container registry is where your game server’s container is stored. All you need to do is make sure the port and protocol types are accurate to your netcode transport’s as to ensure the server adequately listens for connection.

This information can be found in the network manager’s inspector tab. Here is Mirror Network’s sample project port, found under “Transport Configuration”. As for the Prototol Type, is it accurate in this case as this particular sample project by Mirror uses UDP. If you are unsure, refer to your netcode’s documentation to confirm which transport it uses, or select the appropriate option based on your unique choice.  

“New Version Tag” refers to the unique version of your server. This field requires your manual input. We recommend changing the value whenever you proceed with updates to your game server.

For advanced users, Edgegap provides the option use a “Custom Container Registry”. For this tutorial, we will use the Edgegap’s default one.

The second to last step is to select “Build and Push”. This automatically compiles the project into a dedicated Linux server, then create a Docker container which is deployed to Edgegap’s registry.

The last step is to create a new deployment. Under “Status”, you will see it’s progress. Once ready, an URL appears. Copy it by clicking the clipboard button, then paste the information within the network manager’s inspector tab. Under “Network Information”, replace the current “Network Address” by pasting the URL. Make sure to remove the value of the port, which must be inputted in the “Port” field under the “Transport Configuration” section.

Unselect the “Auto Start Server Build” option, as this allows you to connect as a client directly from Unity’s editor.

Finally, start your game scene by clicking the play button atop the editor.

Congrats, your game is now online for the world to play!

Chapter 5: Testing

Evidently, test things first. In our case, using Mirror’s sample project, we confirm the client’s address is correct and can launch a session by selecting “Client”.

Once you are done testing, return to the Edgegap plugin to automatically stop the server instance by selecting “Stop Server”.

That is all for the Mirror plugin on Unity using Edgegap game server and hosting.

The likely next step in your game development will be to connect players. For more information on Edgegap’s free, simple and fully automated matchmaker, you can check out our tutorial.

Thanks for watching!