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 Game Server Hosting (Multiplay).
For testing purposes, you can run the Client and Server in the Editor. This enables inspection of entities, systems, components, etc. while running on both the Server and Client.
To set up the Editor for local multiplayer:
- Go to Project Settings > Entities.
- Set the NetCode Client Target to
ClientAndServer
. - Open Multiplayer PlayMode Tools from Multiplayer > Window: PlayMode Tools.
- Set the PlayMode Type to
Client & Server
.
In the Assets > Resources > MultiplayerServerSettings, you have the ability to configure a server list that will be presented in the play mode Main Menu window. This functionality allows for the establishment of multiple connections and facilitates the use of the Default IP connection.
To begin, 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 drop-down box, select the desired server to establish a connection. If the desired server is not available in the list, you have the option to create a new entry and re-enter play mode. Alternatively, you can manually enter your own IP address using the provided text field.
By default, the project is configured to use the Local IP address. If you are testing the game in the Editor, selecting the Local IP option will allow you to run both the server and client within the Editor, enabling you to play the game.
Once you have selected the appropriate server and IP address, click the Connect button to initiate the connection process.
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.
To build your game and test it locally, you need to build the Client and Server separately.
To make a Windows or Mac Client Build:
- In the Editor, go to Project Settings > Entities to change the NetCode Client Target to
Client
. - Go to Project Settings > Player and change Scripting BackEnd to
iL2CPP
. - Like any other Unity game, make the build by going to File > Build Settings.
- Enable the
Main
andMenu
scenes and set the target platform toWindows, Mac, Linux
. - Press the Build button.
To make a Android Client Build:
- In the Editor, go to Project Settings > Entities to change the NetCode Client Target to
Client
. - Go to Project Settings > Player and select the tab with Android icon change Scripting BackEnd to
iL2CPP
. - In the same window and in the Target Architectures check ARM64 box.
- Like any other Unity game, make the build by going to File > Build Settings.
- Enable the
Main
andMenu
scenes and set the target platform toAndroid
. - Press the Build button.
To make an iOS Build:
- In the Editor, go to Project Settings > Entities to change the NetCode Client Target to
Client
. - Like any other Unity game, make the build by going to File > Build Settings.
- Press the Build & Run button to generate the Xcode project.
To make a Server Build:
- Set the target platform to Dedicated Server.
- Like the Client build, go to File > Build Settings and press the Build button.