This guide will help you create a headless server on Edgegap for a Unity project using Mirror as its networking solution.
This guide will use the open-source sample project
Tanks, which is already available in your Mirror sample, location Assets/Mirror/Examples/Tanks.
The final sample can be found on ourGitHub.
Once ready with your game, head to the
Build screen of the Unity Editor, under
File -> Build Settings in the top menus. Make sure to select the right presets:
- Target Platform should be set to
- Architecture should be set to
- Server build should be ticked (TRUE);
Then press build and select a new empty folder as the file destination. In this document, this folder will be refered as the
[SERVER BUILD] folder.
We will create a docker image containing the dedicated game server in this part. You might also be interested in reading Unity Server in Docker.
If you need more informations about Docker with Edgegap, please refer to this documentation.
Take note of the port you use for network communications, referred as the
[GAME PORT]. By default, the port used is
7777. You can find this information in the Unity Editor, on the
NetworkManager game object, in the
Copy the above lines and paste them in your dockerfile. Modify the
[GAME PORT] placeholders to your game port.
[GAME PORT] opened on both TCP and UDP allow you to use any transport you prefer in the
NetworkManager Mirror component.
Finally, create a file named
boot.sh at the root of the
[SERVER BUILD] folder. It will be executed when starting the image in a container. You can copy the following two lines, make sure to replace the
[YOUR GAME] placeholders with the name of the generated file.
At this point, you should have the following hierarchy:
- Unity generated files
Start a command prompt in the
[SERVER BUILD] folder, and run the following Docker commands:
After these commands, you should be able to see your uploaded image on the Edgegap website if you are using the Edgegap Container Registry. See this doc if you want to use the Edgegap registry. You can also use another private registry.
Navigate to the
Applications & Games page of the website. Click on the
Create New button in the top right hand corner to access the application form.
Here are the fields and how to fill them properly:
- Application name : Can be any notable name you want to use to easily recognize your application among others.
- Image : Can be any specific image you want to use to easily recognize your application among others.
- Version name : You may want to use a version name to describe the scope of the version you are deploying. Examples may be “demo”, “production”, “v1”, “v2”
- Container :
- Registry : “[URL]”, where [URL] is the value from the credentials you can display on the Container Repository page.
- Image repository : “[PROJECT]/[YOUR GAME]”, where [PROJECT] and [YOUR GAME] are the values you used earlier when pushing the docker image.
- Tag : “[TAG]”, where [TAG] is the value you used earlier when pushing the docker image.
- Tick “Using a private repository”
- Private registry username : “[USERNAME]”, where [USERNAME] is the value from your credentials.
- Private registry token : “[TOKEN]”, where [TOKEN] is the value from your credentials.
- Requirements : Left as is.
- Ports :
- Click the
+ Add portlink to add a new port, and add the following entries :
TCP/UDP- disable Verifications
- 3389 - TCP - disable Verifications
- Click the
Once your application has been created, you can press the
Deploy button to proceed with deploying your game server.
Choose the region you want to deploy in, and enter the number of random players you want to generate depending on your game. Check that everything is running smoothly by verifying the following:
- Latest Status should be set to
- In the
Port Mappingtab, you should be seeing the port you set in the application creation form:
The client will need to attempt a connection to the external ports of the Edgegap container that are defined in the
Port Mapping of your game server instance. In the example above, the client must have the port value of the
Transport component of the
NetworkManager set to
31887. This primarily depends on the game you are developing and will most likely be set programmatically in the game’s codebase.
You can set it to the right value in the Unity Editor for a quick test. The connection URL should also be set as the hostname of your game server’s deployed container. This URL can be found in the deployment summary on the dashboard or with the API.
Again, this value will most likely be set programmatically during the client’s communication with the master server/API responsible for the matchmaking process. With the correct information, you should be able to connect to the game server normally and be able to start playing right away.
You now have a Mirror project available to deploy on demand!