# Casual co-op quickstart

> Install the casual co-op quickstart sample to get started with a basic multiplayer game.

This quickstart uses [Netcode for GameObjects](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest) and the [Multiplayer Services SDK](/mps-sdk.md) to create a multiplayer session and spawn a [player prefab](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/manual/components/core/playerobjects.html) for connected players that can be moved using mapped inputs. You can use [Multiplayer Play Mode](https://docs.unity3d.com/Packages/com.unity.multiplayer.playmode@latest) to simulate additional players locally and test the implementation.

Install the sample via the [Multiplayer Center](../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](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.8/manual/components/core/networkmanager.html): 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 [`CreateOrJoinSessionAsync`](/mps-sdk/create-session.md#the-createorjoinsessionasync-method) method.
* [Transport](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/manual/advanced-topics/transports.html): specifies which transport layer to use. By default, Netcode for GameObjects uses the [Unity Transport](https://docs.unity3d.com/Packages/com.unity.transport@latest) package.

In the casual co-op quickstart, the ConnectionSetup GameObject contains these two components, and the NetworkManager is initialized as part of the [connection script](#connecting-to-a-multiplayer-session).

## 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](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/manual/components/core/networkobject.html) 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](https://docs.unity3d.com/6000.3/Documentation/Manual/Prefabs.html) 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](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/manual/components/helper/networktransform.html), which synchronizes a GameObject’s [Transform](https://docs.unity3d.com/6000.3/Documentation/Manual/class-Transform.html), and [NetworkBehaviour](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/manual/components/core/networkbehaviour.html), which allows you to add network-aware scripts to a GameObject. Refer to the [Netcode for GameObjects documentation](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/manual/network-components.html) 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](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/manual/terms-concepts/authority.html) 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](#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](/mps-sdk/create-session.md#the-createorjoinsessionasync-method) method. If you want to handle synchronization yourself, you'll need more complex scripts. Refer to the [Netcode for GameObjects documentation](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/manual/network-synchronization.html) for more information.

The casual co-op quickstart contains a connection script (`SessionConnectorBehaviour.cs`) that has everything you need to get started, and uses configurable components that you can modify to suit your needs.

## Movement scripts

You can add movement to your multiplayer game using Unity's [input system](https://docs.unity3d.com/Manual/Input.html). When used in conjunction with a [NetworkTransform](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/manual/components/helper/networktransform.html) component, updates to a GameObject’s Transform can be synchronized across a network.

The casual co-op quickstart contains a movement script (`PlayerMovementController.cs`) that has everything you need to get started. It defines the `PlayerMovementController` class that listens for input and updates the NetworkTransform component on the player prefab accordingly. You can configure the script depending on which inputs you want to use for movement.

## Multiplayer services

> **Note:**
>
> The Multiplayer Services SDK uses a number of [Unity Gaming Services](/services.md) to provide its functionality, and thus contributes to the billing of those services.

Using the [Multiplayer Services SDK](/mps-sdk.md) 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](/mps-sdk/create-session.md).

## Testing

Once you've created your multiplayer project, you can test it using [Multiplayer Play Mode](https://docs.unity3d.com/Packages/com.unity.multiplayer.playmode@latest?subfolder=/manual/index.html), which creates additional local Editor and Player instances to simulate multiple players connecting to the same game.

The casual co-op quickstart contains a pre-configured [Play mode scenario](https://docs.unity3d.com/Packages/com.unity.multiplayer.playmode@latest?subfolder=/manual/play-mode-scenario/play-mode-scenario-create.html) that spawns an additional Editor instance to test the project. Run this scenario by selecting the **PlayerConnection** scenario from the drop-down menu next to the **Play** button and then pressing **Play**.

## Modify the quickstart

You can use the casual co-op quickstart as the basis of your multiplayer implementation and modify it to further meet your needs. When imported via the Multiplayer Center, it's installed as an embedded package. You can either modify the package directly, or copy assets from the package into your project to edit them.

## Additional resources

* [Netcode for GameObjects](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest)
* [Multiplayer Play Mode](https://docs.unity3d.com/Packages/com.unity.multiplayer.playmode@latest)
