Casual co-op quickstart
Install the casual co-op quickstart sample to get started with a basic multiplayer game.
Read time 4 minutesLast updated 10 hours ago
This quickstart uses Netcode for GameObjects and the Multiplayer Services SDK to create a multiplayer session and spawn a player prefab for connected players that can be moved using mapped inputs. You can use Multiplayer Play Mode to simulate additional players locally and test the implementation. Install the sample via the Multiplayer Center to quickly add it to your project.
Required components
When creating a multiplayer game using Netcode for GameObjects, there are some core components that must always be present to enable basic network functionality:- NetworkManager: specifies the global network settings and must be initialized before any other network-related processes (such as spawning objects) can occur. When using the Multiplayer Services SDK to create a session, NetworkManager initialization and configuration is handled for you as part of the method.
CreateOrJoinSessionAsync - Transport: specifies which transport layer to use. By default, Netcode for GameObjects uses the Unity Transport package.
NetworkObjects and network prefabs
To synchronize a GameObject over a network so that multiple clients can interact with it, you need to attach a NetworkObject component at the root of the GameObject. The NetworkObject component provides the properties and methods required to manage the GameObject’s state. When you create a GameObject prefab that contains a NetworkObject component, it’s referred to as a network prefab. Netcode for GameObjects provides other components to manage networked GameObjects, such as NetworkTransform, which synchronizes a GameObject’s Transform, and NetworkBehaviour, which allows you to add network-aware scripts to a GameObject. Refer to the Netcode for GameObjects documentation for a complete list of available components. The PlayerPrefab asset in the casual co-op quickstart provides a simple example of a network prefab that has a NetworkObject component and a NetworkTransform component. When using the Multiplayer Services SDK to connect and manage a multiplayer session, synchronization of these components is automatically done for you.Add scripts to network prefabs
Just like in single-player game development, adding a script to a prefab allows you to modify the behavior of all instances of that prefab in your game. When working with network prefabs, your scripts must be network-aware, ensuring that clients have the appropriate authority to take whatever action the script entails. Most Netcode for GameObjects components have configuration options that allow you to specify relevant authority settings. The casual co-op quickstart contains a simple movement script that enables four-way movement using mapped inputs by modifying the prefab’s NetworkTransform. Refer to the Movement scripts section for more details.Connecting to a multiplayer session
Most aspects of managing a multiplayer session are automatically handled by the Multiplayer Services SDK, but you need a script in your project to initialize and connect to a session using the CreateOrJoinSessionAsync method. If you want to handle synchronization yourself, you'll need more complex scripts. Refer to the Netcode for GameObjects documentation for more information. The casual co-op quickstart contains a connection script (SessionConnectorBehaviour.csMovement scripts
You can add movement to your multiplayer game using Unity's input system. When used in conjunction with a NetworkTransform component, updates to a GameObject’s Transform can be synchronized across a network. The casual co-op quickstart contains a movement script (PlayerMovementController.csPlayerMovementControllerMultiplayer services
Using the Multiplayer Services SDK is the fastest way to get a basic multiplayer scenario up and running. It provides a single API to manage access to Unity Gaming Services and handles basic synchronization and player management for you when you create a multiplayer session.