Competitive Action Multiplayer template
The Competitive Action Multiplayer template is a project that you can open from the Unity Hub.
The Competitive Action Multiplayer game contains a first-person-shooter (FPS) game loop where you can fire a weapon at other players, die, re-spawn, and restart.
Use this template’s assets and structure as a starting point to build your own game.
It demonstrates first-person shooter (FPS) gameplay in multiplayer and the Netcode for Entities networking structure.
This template uses Netcode for Entities and its client prediction feature, which enables fast-paced gameplay synchronization between players.
This template uses the Multiplayer Services SDK to create a session and connect players in that session. For more information about sessions, refer to Working with the Multiplayer Services SDK.
Use this template as a starting point for your own first-person shooter multiplayer project.
Packages
This template demonstrates the following Unity packages:
- Multiplayer:
- Unity Gaming Services:
- Authentication
- Lobby using Relay or Direct Connect
- Matchmaker
- Multiplay Hosting
- UI Toolkit
- Input system
- Visual effect graph
- URP
Prerequisites
The Competitive Action Multiplayer template has the following requirements:
- Unity version 6000.0.28f1 or later.
Open the template
To create a project that includes the Competitive Action Multiplayer template, follow these steps:
- Open the Unity Hub.
- Select New Project.
- Set the Unity Editor Version to 6000.0.28f1 or later.
- Select Competitive Action Multiplayer.
- Select Download Template.
- Enter a Project name.
- Select Create project.
Explore the template
The Competitive Action Multiplayer template includes tutorials that you can follow to learn how it uses Multiplayer packages and Unity Gaming Services. You can also explore the project’s components, assets, and scenes and enter Play mode to test the game itself.
Follow the template tutorials
When you open the Competitive Action Multiplayer template for the first time, the Welcome Dialog window appears. Use this window to explore the template on your own or start the tutorials.
Note: To open the Tutorial window, go to Tutorials > Show Tutorials > Tutorials.
The Competitive Action Multiplayer template contains the following tutorials:
- Project Overview: Learn the structure of the project.
- Quick Play: Learn how to use PlayMode Tools and the GameBootstrap script to test multiplayer gameplay.
- Unity Gaming Services: Learn how to connect your project to a Unity cloud project and use the Unity Gaming Services products Relay and Lobby.
- Gaming Services: Matchmaker: Learn how to set up Matchmaker for peer-to-peer (P2P) rule-based matchmaking sessions in your project.
- Gaming Services: Multiplay Hosting: Learn how to set up Multiplayer Hosting and build your first Linux Dedicated Server.This tutorial will require you to share payment details for a 6-months free start-up creditt of Multiplayer Hosting.
Understand the assets in the template
The Competitive Action Multiplayer template contains scenes, scripts, and configuration assets that you can explore to learn more about this project.
Scenes
The Competitive Action Multiplayer template contains the following scenes. When you enter Play mode, each scene loads automatically when required:
- The MainMenu contains the GameManager prefab and loads first when you open the project. When you build this project this scene opens by default.
- The GameScene contains the gameplay environment of the game, including spawn points and lighting. You can enter Play mode from this scene to test and iterate on your gameplay without going through the main menu connection setup.
- The ServerScene initializes the dedicated game server. It contains the ServerBootstrap script that controls the game loop on the dedicated server. This script connects the dedicated server instance to the Multiplay Hosting and Matchmaker services and gets the Netcode for Entities server world ready for players to connect.
Scripts
To learn more about how the Competitive Action Multiplayer template, explore the following scripts:
- GameManager manages the game loop. It starts UGS services connection, loads and unloads scenes when a user enters them, and starts the client-server connection through Netcode for Entities.
- GameConnection contains calls to the *Services Session SDK *that group users in a lobby, use matchmaker or a session code to connect the users in that lobby, and retrieve the NetworkEndpoints that connect the Netcode for Entities server to the client world.
- GameBoostrap uses PlayMode Tools to create a session and connect to a local server when a user enters Play mode from the GameScene.
- ClientConnectionSystem connects the Netcode for Entities client world to the server world and automatically reconnects when there is a network issue.
Settings folder
The Settings folder includes the Services folder contains the following assets:
- Configuration files that control the Unity Game Services deployment service.
- The ServicesSettings scriptable object which controls the session settings. For example, you can change from a dedicated server to peer-to-peer (P2P) connection.
The deployment service uploads these files to your cloud project where Matchmaker and Multiplayer Hosting can access them.
Test the gameplay
To test the full game loop, enter Play mode from the MainMenu scene. From there, you can do the following:
- Player Name: Enter the name that appears above your player character when you enter a session.
- Spectator Mode: Join a game as an invisible, flying player character that can't interact with the world.
- Create Game: Create a new game session.
- Join Game: Join an existing game session. When you select this button, enter a session code in the field that appears.
- Matchmake: Connect to multiple users that also use Matchmaking. If no other users join, the session starts with a single user.
- Quit: Exit the game. In Play mode, this button exits Play mode.
Note: When the host quits the game, every user connected to that session disconnects.
To learn how key inputs work in each scene, refer to the Key bindings section.
When you create a game, the GameConnection script creates a host session that other users can join with a session code. When you connect to a session, the join code appears in the session information banner at the top of the Game view.
The session information banner at the top of your Game view also includes your name and the client or host role of this player and connection data that you can use to debug your project.
Note: To use the Unity Game Services SDK, connect your project to the Unity Cloud.
Add simulated clients
You can use the PlayMode Tools window to add simulated clients to your game session or test the project under specific networking conditions.
To add simulated clients to the project:
- Go to Window > Multiplayer > Playmode Tools.
- In the NumThinClients field, enter a value of 1 or higher.
In this project, the thin clients bots don't have any scripted behavior but you can add your own. To learn more about the simulated clients, refer to Testing with Thin Clients.
Limitations
The Relay service doesn't support thin clients. This means that you need to start from the GameScene or use direct connection. To do this:
- Go to the Project window.
- Locate Settings > Services.
- Open ServicesSettings.asset.
- Locate
ConnectionTypeRequested
and set it toDirect.
Test gameplay with virtual players
When you enter Play mode, you can use Multiplayer Play Mode to activate virtual players.
To add virtual players to the project:
- Go to Window > Multiplayer > Multiplayer Playmode.
- In the Virtual Players section, enable the Player 2 checkbox.
- Wait for the Player status to change from inactive to active.
You can add up to three virtual players.
Key bindings
The key bindings in this project change depending on the scene you are currently in. This template supports key bindings on desktop and mobile devices, but some inputs only work on desktop platforms.
Any scene
Action | Keyboard input | Mobile input |
Toggle the session information banner | I | Three-finger tap |
Key bindings in the GameScene
Action | Keyboard input | Mobile input |
Move | W, A, S, D | Left virtual joystick |
Look around | Move Mouse | Right virtual joystick |
Jump | Space | Left virtual Jump button |
Aim | Right mouse button | Left virtual aim button |
Shoot | Left mouse button | Left virtual Shoot button |
Display or hide the pause menu | Esc | Left upper corner Menu button |
Key bindings in the GameScene (desktop only)
Action | Keyboard input |
Destroy player character | K |
Return to Main Menu | F1 |
Key bindings in the MainMenu scene (desktop only)
Action | Keyboard input |
Quit | F1 |
Host a game | 1 |
Join a game | 2 |