…
|
||
---|---|---|
.. | ||
AdditionalBuildFiles | ||
Assets | ||
Packages | ||
ProjectSettings | ||
README.md |
README.md
Dedicated Game Server
The Dedicated Game Server sample project uses Netcode For GameObjects (NGO). It also demonstrates the structure of a project that uses the dedicated server and the tools that you can use to configure it.
Sample Overview
The dedicated server sample scene contains a small maze with interactive doors and patrolling AI characters. Player characters can move around and open or close the doors using the switches nearby. You can use this sample scene to learn how to do the following:
- Integrate features from the Dedicated Server and Multiplayer Play Mode packages with Netcode for GameObjects to with the dedicated server architecture.
- Set default comand line arguments
- Use multiplayer roles.
- Use the dedicated server with multiplayer play mode.
- Strip GameObjects from the clients and server.
- Integrate a project that uses the dedicated server with the Game Server Hosting and Matchmaker services.
Exploring the Sample
The dedicated server sample has a different workflows when you select the Client or Server multiplayer role. Both servers and clients start at the StartupScene, where Unity initializes the relevant systems.
The server multiplayer role
Unity moves the server to the game scene, where it waits for clients to connect.
The client multiplayer role
Unity moves clients to the Metagame scene. From here you can use the main menu to connect to a server. Select the Find Match to join a matchmaking queue to connect to a server. Select Join with Direct IP to connect to a server directly when you know its IP address. In both cases Unity moves clients to the game scene when the client connects.
Autoconnect mode
Use the autoconnect mode to automatically connect as a client to a local server without moving to the Metagame scene. You can use this mode to speed up testing.
To enable autoconnect mode on the main editor, do the following:
- Set the editor multiplayer role to Client.
- Open the StartupScene
- In the Hierarchy window, select the ApplicationEntryPoint GameObject.
- In the ApplicationEntryPoint component, select the Autoconnect if client checkbox .
Set up the dedicated game server sample
Register the project with Unity Gaming Services (UGS)
This sample uses the following services from Unity Game Services (UGS) to help connect between players:
- Game Server Hosting
- Matchmaker
To use these services inside your project, create an organization inside the Unity Dashboard.
Set up the Game Server Hosting service
To set up the Game Server Hosting (Multiplay) service, do the following:
- Test the dedicated server sample in a build.
- Generate the build that Unity uploads to the Game Server Hosting service. To learn how to do this, refer to Create a build.
Set up the Matchmaker service
Use the Matchmaker service to connect clients to the servers hosted by Game Server Hosting and control when a server starts. To use this service, install and set up Matchmaker.
Note: Name your Queue "Queue01" for the sample to use it automatically.
Test the dedicated game server sample in multiplayer
To run the dedicated game server sample as a multiplayer game, you can use Multiplayer Play Mode to run multiple instances of the game locally, or connect to a friend over the internet. For more information, refer to Testing locally.
To change the total number of players allowed in a single session, do the following:
- Open the StartupScene
- In the Hierarchy window, select the ApplicationEntryPoint GameObject.
- In the ApplicationEntryPoint component, adjust the numbers in the Min Players and Max Players fields.
Use Multiplayer Play Mode to test the dedicated game server sample
Multiplayer Play Mode allows quicker testing iterations without requiring to generate builds. To use this feature, you will first have to enable one or more virtual players. Each of those players can be a client or a server. To start testing, assign the server role to either the main editor or a player, then assign the client role to the rest. You can assign those roles using the same dropdown as the one on the main editor. You will then be able to have them connect to each other via direct connection, or have clients connect to a server hosted by Game Server Hosting via Matchmaker if both services are already setup in the dashboard (see the above sections about setting up Game Server Hosting and Matchmaker). However, make sure that the server build that is hosted is up to date.
Test the dedicated server sample in a build
To generate a build to test the sample locally or over the internet do the following:
- Open the Build window (menu: DedicatedGameServerSample > Builds).
- Select the Toggle... option for the platform(s) you want to build for.
- Select Build Client(s), Build Server(s), or Build Client(s) and Server(s) to generate the builds.
Set up multiplayer in a local server
After you create a build to test the sample, you can run a server build to host the server and run client builds to join the server. To connect to a local server, select Join with Direct IP and use the IP address 127.0.0.1.
Set up multiplayer over the internet
To test the dedicated server sample in multiplayer over the internet, every client needs to use the same build version. This means you need to share the build executables to each client. Once each client has the same build, you can connect using one of the following ways:
- Use a direct IP address to connect to a server hosted by one of the playtesters. Note: the person hosting the server will need to open their ports and share their public IP address to allow clients to connect to the server.
- Use the Matchmaker and Game Server Hosting services to connect to a server on the cloud. Both of these options work in the editor and in Multiplayer Play Mode clones, but a build version stays the same acrross multiple clients. This reduces the risk of incompatibilities if you make any changes in the editor.
Use a direct IP address
To use a public IP address to connect players to the server in a client build, do the following:
- Run the server executable on a player's machine.
- Open the player's port on the server to allow other players to connect to it.
- On Clients, enter the opened port and public IP address of the server in the Join with Direct IP screen of the game.
💡 Bitesize Readme
Check out our main Bitesize Samples GitHub Readme for more documentation, resources, releases, contribution guidelines, and our feedback form.