- Contents and Quick Links
- Megacity Multiplayer Overview
- Megacity Multiplayer Prerequisites
- Important Note Before You Begin
- Get Megacity Multiplayer
- Get Started
- Add Unity Gaming Services (UGS)
- Test Your Multiplayer Setup
- Gameplay Controls
- Index of Resources in this Project
- Troubleshooting
- Disclaimer
- License
Megacity Multiplayer is an action-packed, shooter game based on the original Megacity sample. It leverages the power of Netcode for Entities for an immersive, multiplayer experience that can support 64+ players simultaneously. The latest DOTS packages and Unity Gaming Services (UGS) enhances the Megacity Multiplayer user experience. Megacity Multiplayer showcases how to create engaging and immersive multiplayer experiences with a suite of netcode and multiplayer tools, tech, and services.
Some important points of this demo are:
Large-scale streaming
and rendering with the Entity Component System (ECS for Unity)- 64+ players per game session
- Server-authoritative gameplay with feature prediction, interpolation, and lag compensation using Netcode for Entities
- Unity Gaming Services (UGS) integration for Game Server Hosting, Matchmaking, and Vivox voice chat
High Definition Render Pipeline (HDRP)
- Cross-platform support for Windows and Mac
Important Note:
This repository is deprecated and will no longer be maintained. For the latest features of ECS packages and the most recent version of this sample, please refer to the following repository: Megacity Metro. However, if you are specifically interested in Large-scale streaming
or utilizing HDRP
, please clone this repository.
Megacity Multiplayer is compatible with Unity 2022 LTS and is currently tested on Windows and Mac. You can download the editor using the following link:
- Unity Website: Download Unity LTS
- Operating System: Mac OS X 10.15.7
- CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
- RAM: 32GB
- GPU: AMD Radeon Pro Vega 20
- Storage: 20GB
- Operating System: Windows 10 64bit
- CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
- RAM: 32GB
- GPU: NVIDIA GeForce GTX 1650 with Max-Q Design
- Storage: 20GB
The Megacity Multiplayer sample is large, so the first time cloning and playing the sample may take more time than expected. Subsequent plays should load much quicker because of caching.
First time clone and load time estimates:
- Cloning the Megacity Multiplayer repo: Up to 20 min
- Opening the project with library build: Up to 20 min
- When going into the main scene, subscenes need to import: Up to 20 min
- When going into the playmode, server world is created: Up to 30 min
To get the Megacity Multiplayer sample, you can clone the project using Git. Please note that direct download of the project is not currently supported for this repository.
Before you can clone the project, you must install Git Large File Support (LFS). Megacity Multiplayer uses Git LFS to handle all large assets required locally. Refer to Git LFS installation options for instructions on Windows and Mac.
After you clone the project, follow these steps to start playing:
- Install a compatible Unity Editor version. During install make sure to include Standalone Support and Dedicated Server Support for Windows/Mac.
- To add the project to the Unity Hub, click the Add button and select the root folder of the cloned project.
- Note: The first time you open the project may take longer than usual because Unity is importing all the assets.
- Prior to entering playmode, it may be necessary to create the Entities scene cache. To achieve this, please open Main scene located in
Scenes/Main.scene
.
- Important: To monitor the progress of the Entities scene cache loading, navigate to Window > General > Process. This action will open the Background Tasks Window, displaying a loading bar.
- When all subcenes has been created, open the Menu scene located in
Scenes/Menu
. - Click the Play button to start.
The main menu offers the following options:
- Single Player
- Guided Flight: This mode enables automatic navigation through the city using Cinemachine path to establish the route.
- Free Flight: In this game mode, you can drive a vehicle and explore the entire city at your own pace.
- Multiplayer, in the "Mode" radio button, you can choose from the following options:
- Settings, it is possible to find the option to configure the game settings based on the hardware to enhance your overall gaming experience. This option is also available in the Main scene at runtime.
Within the Resources
directory, it is possible to find an asset named MultiplayerServerSettings
.
This asset allows to configure the Server List that appears in the Menu.
Furthermore, there are supplementary options available:
- Auto Run Game Mode In Editor Main: This option lets you choose between running the main scene directly in Singleplayer or Multiplayer mode, bypassing the Menu scene.
- Auto Run Single Player Game Mode In Editor Main: The availability of this option depends on the selection of "Auto Run Game Mode In Editor Main" as "Single Player."
Megacity Multiplayer uses several services from UGS to facilitate connectivity between players. To use these services inside your project, you need a Unity Account and create an organization within the Unity Dashboard.
You can still use Megacity Multiplayer without UGS, but for a better multiplayer experience, it is recommended to use the following services:
Game Server Hosting, formerly known as Multiplay, is a robust and flexible infrastructure for hosting multiplayer games. It ensures a smooth operation of your game by delivering proven performance and scalability. With Game Server Hosting, you can launch your multiplayer titles with confidence, knowing that you have the support of a reliable global platform. The enables you to spend less time troubleshooting and more time building your game with the help of comprehensive documentation, samples, and software development kits (SDKs) designed for interoperability. To get started with Game Server Hosting, refer to the official documentation.
Warning: Game Server Hosting is a pay-as-you-go service with a free tier. You must sign up for UGS services with a credit card to start using Game Server Hosting. If you exceed the free tier usage allowance, you will be charged. See our Billing FAQ to learn more.
To use Game Server Hosting in your project, you need to Integrate the Game Server Hosting service from the Unity Dashboard.
Note: You must be an Owner or Manager of your organization to enable Game Server Hosting.
After you integrate Game Server Hosting, you must create a build, a build configuration, a fleet, and a test allocation.
Tip: Check out our YouTube video How to set up Game Server Hosting.
For Megacity Multiplayer, we use the following Game Server Hosting configuration:
- Launch parameters:
-ip $$ip$$ -port $$port$$ -queryport $$query_port$$ -logFile $$log_dir$$/$$timestamp$$-Engine.log
- CPU Speed: 1500 MHz
- Memory: 1600 MB
Matchmaker is a versatile tool that enables you to customize matches in your game. It offers fast and efficient matches, multi-region orchestration, and backfill options. With its flexible configuration, dynamic scalability, and robust rule engine, Matchmaker simplifies matchmaking while supporting complex game loops. For more information, consult the Matchmaker Quick Start Guide.
To use Matchmaker in your project, you must Enable and Integrate the Matchmaker service from the Unity Dashboard.
For Megacity Multiplayer, we use the following Matchmaker configuration:
Creating the queue:
- Maximum players on a ticket: 12
Creating a default pool:
- Timeout: 60 seconds
For Matchmaker rules, we use the following configuration:
- Backfill enabled: true
- Team count min: 1
- Team count max: 1
- Player count min: 64
- Player count max: 256
- Relaxation 1: Replace min, Replacement value: 32, at seconds: 5
- Relaxation 2: Replace min, Replacement value: 1, at seconds: 10
After configuring the services on the dashboard website, navigate to Edit > Project Settings > Service and choose your organization and project ID.
Next, click on the play button to initiate the game. To access the Matchmaking services, navigate to the main menu and select "Matchmake" from the radio button menu, followed by clicking the "Find Match" button.
Once the "Find Match" button is clicked, the Matchmaking services will initiate the connection process with the server. During this time, a circular loading indicator will be presented to signify that the system is in the process of establishing the connection. Once the connection is established, you will be able to start gameplay.
Vivox is a voice chat service that enables players to communicate with each other in-game. To use Vivox, you need to connect your project to Vivox from the Unity Editor and enable Vivox in the Unity Dashboard.
For more information about Vivox, and how to use it you can read the Vivox quickstart guide.
Megacity Multiplayer 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 > Settings > Gameplay > 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, navigate to the Connect option in the radio button menu. From the drop-down box, select the desired IP address to establish a connection. If the desired IP address 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 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). For example, if you open Entities Hierarchy, you can select the desired World to inspect from the dropdown. See the following image:
To build your game and test it locally, you need to build the Client and Server separately.
To make a Client 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.
- Enable the
Megacity
scene and set the target platform isWindows, Mac, Linux
. - Press the Build button.
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.
Input | Action |
---|---|
Mouse Movement / Arrow Keys | Steering |
Left Click / Space | Shoot |
W/S | Thrust / Reverse |
A/D | Steering |
E/Q | Roll |
Tab | Settings |
V | Toggle Vivox |
P | Netcode Panel Stats |
No Key Press | Auto-Level |
- Vehicle Input System
- PlayerVehicleJobs
- SetupPlayerInfoSystem
- ShootingSystem
- BoundSystem
- SpawnPoint
- UpdatePlayerRankSystem
Report bugs in Megacity Multiplayer using GitHub issues. If the bugs are related to the Entities packages, use the Entities GitHub issues.
This repository does not accept pull requests, GitHub review requests, or any other GitHub-hosted issue management requests.
Megacity Multiplayer is licensed under the Unity Companion License. See LICENCE for more legal information.