Megacity Metro is server-authoritative, which means the server has ultimate authority and control over the game's state and rules. To test the game, a server needs to be running, and clients need to connect to the server. This can be done in the Editor, locally, or through Multiplay Hosting.
NOTE!: Megacity Metro now relies on the new Session API introduced in the Multiplayer Services SDK package. Sessions require you to set up UGS for local development too.
To build your game and test it locally, you need to build the Client and Server separately.
You can set up various build profiles that fit your needs per platform, or simply use the default settings defined by the given platform.

IMPORTANT!: Before building any Clients in the Editor:
Go to Project Settings > Entities to change the NetCode Client Target to
Client.Ensure that under Project Settings > Player the Scripting BackEnd is set to
iL2CPP.Enable the
MainandMenuscenes in theScene Listin the File > Build Profiles menu
-
To make a Windows or Mac Client Build:
- Like any other Unity game, make the build by going to File > Build Profiles.
- Set the target platform to
Windows/ Mac. - Press the Build button.
-
To make a Android Client Build:
- In the Player settings window and in the Target Architectures check ARM64 box.
- Like any other Unity game, make the build by going to File > Build Profiles.
- Press the Build button.
-
To make an iOS Build:
- Like any other Unity game, make the build by going to File > Build Profiles.
- Press the Build & Run button to generate the Xcode project.
-
To make a Dedicated Linux Server Build:
- Like the Client builds, go to File > Build Profiles
- Set the target platform to Linux Server.
- and press the Build button.
- [optional]: Name your executable to
Server
-
To make a Windows or macOS server Build:
- Like the Client builds, go to File > Build Profiles
- Set the target platform to Windows Server or macOS Server.
- and press the Build button.
- [optional]: Name your executable to
Server
NOTE!: Megacity Metro Server builds can be started locally, but do require authentication tokens acquired from UGS.
- Build a Dedicated Game Server
- Create and configure a service account with the Unity Environments Viewer role
Make sure to save your API Secret and Key into environment variables
Windows
- Locate your Windows Server build folder
- Open a Powershell window in it
- Run your Server executable with the following parameters:
.\'Server' -port 7979 --api-key-id $env:API_KEY --api-key-secret $env:API_SECRET -define:USING_UNITY_LOGGING
macOS
- Locate your macOS Server build folder in a terminal
- Run your Server executable with the following parameters:
exec ./Server -port 7979 --api-key-id $API_KEY--api-key-secret $API_SECRET
Linux
- Locate your Linux Server build folder in a terminal
- Run your Server executable with the following parameters:
./Server -port 7979 --api-key-id $API_KEY--api-key-secret $API_SECRET
To speed up your development, you can containerize your Dedicated Server build, here are the suggested steps:
- Set up Docker Desktop
- Build your Dedicated Server
- Locate the build folder
- Create a file containing the API Key and Secret env variable definitions
#name it .env API_KEY=<YOUR_API_KEY> API_SECRET=<YOUR_SECRET>
- Paste the following
DOCKERFILEnext to your binaries.More details about the suggested docker image can be found here.# Suggested image to start with FROM unitymultiplay/linux-base-image:latest # Expose all variables stored in the .env file set -a source .env set +a WORKDIR /game COPY --chown=mpukgame . . # Set permissions RUN chmod +x ./Server.x86_64 # Call the server with the required parameters ENTRYPOINT ENTRYPOINT [ "./Server.x86_64", "-port", "7979", "--api-key-id", "$API_KEY", "--api-key-secret", "$API_SECRET", "-define:USING_UNITY_LOGGING" ]
Execute the following command from the folder of the built executables:
docker build --platform linux/amd64 -t megacity-metro2:latest .Ensure to specify the UDP protocol on start:
docker run -p 7979:7979/udp --name megacity-metro2 megacity-metro2:latestIf you run into difficulties authenticating, confirm the credentials using the steps described below (borrowed from here):
curl -H https://services.api.unity.com/auth/v1/token-exchange
# Returns hash
echo -n "<KEY_ID>:<KEY_SECRET>" | base64
# Returns token
curl -X POST -H "Authorization: Basic <HASH>" \
"https://services.api.unity.com/auth/v1/token-exchange?projectId=<PROJECT_ID>&environmentId=<ENVIRONMENT_ID>"As mentioned in the docs and steps above, your service account must be able to get its environments like so:
curl -H "Authorization: Basic <HASH>" \
"https://services.api.unity.com/unity/v1/projects/<PROJECT_ID>/environments"- Unable to connect
Make sure that you are exposing the proper UDP port when running your docker image.
You can also add net tools to your docker image to debug the network connection from within the container.
# need to be root user to install any packages
USER root
RUN apt-get update && apt-get install -y \
net-tools \
tcpdump \
curl && apt-get clean
# unsafe! do not ever use in production!
# Using chmod to modify file permissions for tcpdump is not recommended for security reasons because it can open up your system to abuse if someone exploits tcpdump or gains access to your container.
RUN chmod u+s /usr/sbin/tcpdump
# Restore the runtime user
USER mpukgameFor testing purposes, you can run the Client in the Unity Editor.
This enables inspection of entities, systems, components, etc. in the Entities Hierarchy window.
When you are running both the Server and Client in your local environment you can inspect both Netcode Worlds.
To set up the Editor for locally hosted multiplayer:
- Open Multiplayer PlayMode Tools from Window > Multiplayer > PlayMode Tools.
- Set the PlayMode Type to
Client & Server.
NOTE!: Setting the playmode type to
Client & Serveris required for the local server's world to show up in your entities hierarchy when you are running your clinet from the editor.
First of all start a server locally, or spawn one using matchmaking.
- Click the play button in the Unity Editor to launch the game. Once the game is running and you are in the Main Menu, change the mode to Connect in the Menu.
From the Session Browser, select the desired Session to establish a connection with. If the desired server Session is not available in the list, you can press on the [REFRESH] button to trigger a new query.
Now, when you play the game from the Editor, the Server and Client run together on your local machine. To inspect Client or Server entities, systems, etc., you can use the Entities window (Window > Entities > Hierarchy). For example, if you open Entities Hierarchy, you can select the desired World to inspect from the dropdown.

