Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.

Commit 23b7ab8

Browse files
jabbacakesVic-CooperDSchroerr-machLagowiecDev
authored
Develop into main (#1291)
Co-authored-by: Vic Cooper <[email protected]> Co-authored-by: Dominick <[email protected]> Co-authored-by: Rémi MACH <[email protected]> Co-authored-by: LagowiecDev <[email protected]> Co-authored-by: amanda-butler-unity <[email protected]> Co-authored-by: Noel Stephens <[email protected]> Co-authored-by: Griffin of Innatical <[email protected]> Co-authored-by: Christopher Pope <[email protected]> Co-authored-by: Steve Diniro <[email protected]> Co-authored-by: s-omeilia-unity <[email protected]> Co-authored-by: Alex Martin <[email protected]> Co-authored-by: Monaxys <[email protected]> Co-authored-by: Flap27 <[email protected]> Co-authored-by: NRTnarathip <[email protected]> Co-authored-by: Elfi0Kuhndorf <[email protected]> Co-authored-by: CodeSmile <[email protected]> Co-authored-by: Frank Luong <[email protected]> Co-authored-by: Sue Arkin <[email protected]>
1 parent 7f3b6bb commit 23b7ab8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1137
-93
lines changed

docs/learn/distributed-authority-quick-start.md

Lines changed: 158 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ Before you begin, you need the following:
1111

1212
- An active Unity account with a valid license.
1313
- The [Unity Hub](https://unity.com/download).
14-
- A supported version of the Unity Editor. Refer to the [Netcode for GameObjects requirements](https://docs-multiplayer.unity3d.com/netcode/current/installation).
15-
16-
## Install packages
17-
18-
- Install the latest `com.unity.services.multiplayer` Multiplayer Services package.
19-
- Install the latest `com.unity.netcode.gameobjects` Netcode for GameObjects package.
14+
- A supported version of the Unity 6 Editor.
15+
- Additional requirements information can be found here: [Netcode for GameObjects requirements](https://docs-multiplayer.unity3d.com/netcode/current/installation).
2016

2117
## Project setup
2218

@@ -28,14 +24,29 @@ Before you begin, you need the following:
2824

2925
![connect unity cloud](/img/learn/distributed-authority-quick-start/connect-unity-cloud.png)
3026

31-
:::note Access during alpha and beta
32-
During alpha and beta, you need to request access to the distributed authority service. To do so, provide your Unity contact with the ID of the Unity Cloud project you created.
33-
:::
27+
## Install packages
3428

35-
## Connection setup
29+
- Install the latest `com.unity.netcode.gameobjects` Netcode for GameObjects **v2.0.0** package.
30+
- Install the latest `com.unity.services.multiplayer` Multiplayer Services package.
31+
32+
## Netcode for GameObjects setup
33+
34+
1. Using the SampleScene, add a new *Empty* object and name it *NetworkManager*.
35+
36+
2. Attach a Network Manager component to it.
37+
![add network manager](/img/learn/distributed-authority-quick-start/network-manager.png)
38+
39+
3. Under the Network Settings, set the **Network Topology** property to **Distributed Authority**.
40+
![set network topology](/img/learn/distributed-authority-quick-start/network-topology.png)
41+
42+
4. Under **Network Transport**, select **UnityTransport** from the list of options to add.
43+
![use unity transport](/img/learn/distributed-authority-quick-start/unity-transport.png)
44+
45+
5. Save any changes to your objects and scene.
3646

37-
1. Create a new script called *ConnectionManager.cs*. This script provides a user interface and connects to a distributed authority service session:
47+
## Connection setup
3848

49+
1. Create a new script called *ConnectionManager.cs*. This script provides a user interface and the script logic required to connect to a distributed authority service session:
3950
```cs
4051
using System;
4152
using System.Threading.Tasks;
@@ -51,6 +62,7 @@ public class ConnectionManager : MonoBehaviour
5162
private int _maxPlayers = 10;
5263
private ConnectionState _state = ConnectionState.Disconnected;
5364
private ISession _session;
65+
private NetworkManager m_NetworkManager;
5466

5567
private enum ConnectionState
5668
{
@@ -59,10 +71,29 @@ public class ConnectionManager : MonoBehaviour
5971
Connected,
6072
}
6173

62-
private async void Awake()
63-
{
64-
await UnityServices.InitializeAsync();
65-
}
74+
private async void Awake()
75+
{
76+
m_NetworkManager = GetComponent<NetworkManager>();
77+
m_NetworkManager.OnClientConnectedCallback += OnClientConnectedCallback;
78+
m_NetworkManager.OnSessionOwnerPromoted += OnSessionOwnerPromoted;
79+
await UnityServices.InitializeAsync();
80+
}
81+
82+
private void OnSessionOwnerPromoted(ulong sessionOwnerPromoted)
83+
{
84+
if (m_NetworkManager.LocalClient.IsSessionOwner)
85+
{
86+
Debug.Log($"Client-{m_NetworkManager.LocalClientId} is the session owner!");
87+
}
88+
}
89+
90+
private void OnClientConnectedCallback(ulong clientId)
91+
{
92+
if (m_NetworkManager.LocalClientId == clientId)
93+
{
94+
Debug.Log($"Client-{clientId} is connected and can spawn {nameof(NetworkObject)}s.");
95+
}
96+
}
6697

6798
private void OnGUI()
6899
{
@@ -122,70 +153,139 @@ public class ConnectionManager : MonoBehaviour
122153
}
123154
```
124155

125-
2. Attach this script to a new object in your scene.
126-
156+
2. Add the `ConnectionManager` component script you created to the *NetworkManager* object.
127157
![add connection manager](/img/learn/distributed-authority-quick-start/create-connection-manager.png)
128158

129-
## Netcode for GameObjects setup
130-
131-
1. Create a new object in your scene called *NetworkManager*. Attach a Network Manager component to it.
132-
133-
![add network manager](/img/learn/distributed-authority-quick-start/network-manager.png)
134-
135-
2. Set **Session Mode** to **Distributed Authority**.
136-
137-
![set session mode](/img/learn/distributed-authority-quick-start/session-mode.png)
138-
139-
3. Under **Network Transport**, select **UnityTransport** from the list of options to add.
140-
141-
![use unity transport](/img/learn/distributed-authority-quick-start/unity-transport.png)
142-
143-
4. Save any changes to your objects and scene.
144-
145159
## Adding gameplay
146160

147161
1. Create a new Script called *PlayerCubeController.cs*:
148-
149162
```cs
150-
using Unity.Netcode;
151163
using Unity.Netcode.Components;
152164
using UnityEngine;
165+
#if UNITY_EDITOR
166+
using Unity.Netcode.Editor;
167+
using UnityEditor;
168+
/// <summary>
169+
/// The custom editor for the <see cref="PlayerCubeController"/> component.
170+
/// </summary>
171+
[CustomEditor(typeof(PlayerCubeController), true)]
172+
public class PlayerCubeControllerEditor : NetworkTransformEditor
173+
{
174+
private SerializedProperty m_Speed;
175+
private SerializedProperty m_ApplyVerticalInputToZAxis;
176+
177+
178+
public override void OnEnable()
179+
{
180+
m_Speed = serializedObject.FindProperty(nameof(PlayerCubeController.Speed));
181+
m_ApplyVerticalInputToZAxis = serializedObject.FindProperty(nameof(PlayerCubeController.ApplyVerticalInputToZAxis));
182+
base.OnEnable();
183+
}
184+
185+
186+
public override void OnInspectorGUI()
187+
{
188+
var playerCubeController = target as PlayerCubeController;
189+
190+
191+
playerCubeController.PlayerCubeControllerPropertiesVisible = EditorGUILayout.BeginFoldoutHeaderGroup(playerCubeController.PlayerCubeControllerPropertiesVisible, $"{nameof(PlayerCubeController)} Properties");
192+
if (playerCubeController.PlayerCubeControllerPropertiesVisible)
193+
{
194+
EditorGUILayout.PropertyField(m_Speed);
195+
EditorGUILayout.PropertyField(m_ApplyVerticalInputToZAxis);
196+
}
197+
EditorGUILayout.EndFoldoutHeaderGroup();
198+
199+
200+
EditorGUILayout.Space();
201+
202+
203+
playerCubeController.NetworkTransformPropertiesVisible = EditorGUILayout.BeginFoldoutHeaderGroup(playerCubeController.NetworkTransformPropertiesVisible, $"{nameof(NetworkTransform)} Properties");
204+
if (playerCubeController.NetworkTransformPropertiesVisible)
205+
{
206+
// End the header group prior to invoking the base OnInspectorGUID in order to avoid nested
207+
// foldout groups.
208+
EditorGUILayout.EndFoldoutHeaderGroup();
209+
// If NetworkTransform properties are visible, then both the properties any modified properties
210+
// will be applied.
211+
base.OnInspectorGUI();
212+
}
213+
else
214+
{
215+
// End the header group
216+
EditorGUILayout.EndFoldoutHeaderGroup();
217+
// If NetworkTransform properties are not visible, then make sure we apply any modified properties.
218+
serializedObject.ApplyModifiedProperties();
219+
}
220+
}
221+
}
222+
#endif
223+
153224

154-
public class PlayerCubeController : NetworkBehaviour
225+
public class PlayerCubeController : NetworkTransform
155226
{
156-
public float speed = 20;
227+
#if UNITY_EDITOR
228+
// These bool properties ensure that any expanded or collapsed property views
229+
// within the inspector view will be saved and restored the next time the
230+
// asset/prefab is viewed.
231+
public bool PlayerCubeControllerPropertiesVisible;
232+
public bool NetworkTransformPropertiesVisible;
233+
#endif
157234

158-
private NetworkTransform _transform;
159235

160-
private void Start()
161-
{
162-
_transform = GetComponent<NetworkTransform>();
163-
}
236+
public float Speed = 10;
237+
public bool ApplyVerticalInputToZAxis;
164238

165-
private void Update()
166-
{
167-
var movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
168-
_transform.transform.position += movement * speed * Time.deltaTime;
169-
}
170-
}
171-
```
172239

173-
2. Create a new prefab called *PlayerCube* and open it for editing.
174-
- Attach the *PlayerCubeController* to the prefab. When prompted to add a NetworkObject, select **Yes**.
175-
- Attach a Network Transform component as well. Make sure all the **Ownership** flags are unchecked.
240+
private Vector3 m_Motion;
241+
176242

177-
![setup network transform](/img/learn/distributed-authority-quick-start/network-transform.png)
243+
private void Update()
244+
{
245+
// If not spawned or we don't have authority, then don't update
246+
if (!IsSpawned || !HasAuthority)
247+
{
248+
return;
249+
}
178250

179-
3. Attach a child object in the prefab. Select the root of the prefab, right-click, and select **3D Object > Cube**.
180251

181-
![add the cube](/img/learn/distributed-authority-quick-start/create-cube.png)
252+
// Handle acquiring and applying player input
253+
m_Motion = Vector3.zero;
254+
m_Motion.x = Input.GetAxis("Horizontal");
182255

183-
4. Save all changes to the prefab.
184256

185-
5. Open the Network Manager, navigate to **Prefab Settings**, and set the **Default Player Prefab** to be **PlayerCube**.
257+
// Determine whether the vertical input is applied to the Y or Z axis
258+
if (!ApplyVerticalInputToZAxis)
259+
{
260+
m_Motion.y = Input.GetAxis("Vertical");
261+
}
262+
else
263+
{
264+
m_Motion.z = Input.GetAxis("Vertical");
265+
}
186266

187-
![set the prefab](/img/learn/distributed-authority-quick-start/player-cube.png)
188267

268+
// If there is any player input magnitude, then apply that amount of
269+
// motion to the transform
270+
if (m_Motion.magnitude > 0)
271+
{
272+
transform.position += m_Motion * Speed * Time.deltaTime;
273+
}
274+
}
275+
}
276+
```
277+
2. In the open *SampleScene*, create a 3D cube and name it *PlayerCube*.
278+
![create PlayerCube object](/img/learn/distributed-authority-quick-start/player-cube.png)
279+
3. Add a `NetworkObject` component to the *PlayerCube*.
280+
![add a NetworkObject component](/img/learn/distributed-authority-quick-start/add-networkobject.png)
281+
4. Add the *PlayerCubeController* to the *PlayerCube*.
282+
![add the PlayerCubeController component](/img/learn/distributed-authority-quick-start/add-playercubecontroller.png)
283+
5. Create a Prefabs folder in the root Assets folder.
284+
6. Drag and drop the *PlayerCube* object into the newly created Prefabs folder.
285+
![create the player cube prefab](/img/learn/distributed-authority-quick-start/create-playercube-prefab.png)
286+
6. Delete the *PlayerCube* object from your scene.
287+
5. Open the Network Manager, navigate to **Prefab Settings**, and set the **Default Player Prefab** to be the newly created *PlayerCube*.
288+
![set the default player prefab](/img/learn/distributed-authority-quick-start/assign-default-player-prefab.png)
189289
6. Save all changes to the scene.
190290

191291
## Next steps

docusaurus.config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,17 @@ module.exports = {
369369
lastVersion: "current",
370370
versions: {
371371
current: {
372-
label: "1.1.0",
372+
label: "1.2.0",
373373
path: "current",
374374
},
375+
"1.1.0": {
376+
label: "1.1.0",
377+
path: "1.1.0",
378+
},
379+
"1.0.0": {
380+
label: "1.0.0",
381+
path: "1.0.0",
382+
},
375383
"1.0.0": {
376384
label: "1.0.0",
377385
path: "1.0.0",

mppm/about.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ description: Overview of Multiplayer Play Mode
66

77
Use Multiplayer Play Mode to test multiplayer functionality within the Unity Editor. You can simulate up to four players (the Main Editor and three Virtual Players) simultaneously on the same development device while using the same source assets on disk. Multiplayer Play Mode can help you create multiplayer development workflows that reduce project build times, run it locally, and test the server-client relationship.
88

9+
## Compatibility
10+
11+
Multiplayer Play Mode version 1.1.0 is compatible with Unity Editor versions 6000.0.3f1 or later.
12+
913
## Multiplayer Play Mode terminology
1014

1115
The following have specific meaning in relation to Multiplayer Play Mode:

mppm/install.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ title: Install Multiplayer Play Mode
44
description: How to install Multiplayer Play Mode
55
---
66

7-
To begin testing your multiplayer functionality, you must first install the Multiplayer Play Mode package.
7+
You can use Multiplayer Play Mode version 1.1.0 in Unity Editor versions 6000.0.3f1 or later. Multiplayer Play mode versions 1.0.0 and earlier are compatible with Unity version 2023.1 or later.
8+
To install the Multiplayer Play Mode package, follow these steps:
89

910
1. Open Unity Hub.
10-
2. Select a Project.
11+
2. Select a Project to open it.
1112
3. In the Editor's menu bar, navigate to **Window** > **Package Manager**.
1213
4. Select **Unity Registry**.
1314
5. Select the **Multiplayer Play Mode** package.

mppm/release-notes/release-notes.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ title: Release notes
44
description: Release notes for Multiplayer Play Mode including new features, updates, bug fixes, and known issues.
55
---
66

7+
## [1.2.0] - 2024-06-04
8+
9+
### Added
10+
- Added tooltips to the preferences window
11+
12+
### Fixed
13+
- Fixed an issue that hid Multiplayer roles when you reinstalled the Dedicated Server Package.
14+
- Fixed the main view window so that when you make it smaller the UI is not affected.
15+
716
## [1.1.0] - 2024-04-24
817

918
### Added
@@ -22,7 +31,7 @@ description: Release notes for Multiplayer Play Mode including new features, upd
2231
- The escape key no longer closes virtual player windows on Windows devices.
2332
- Fixed issues with heartbeat timeout.
2433
- Removed the forward slash **/** character from tags because it's for drop-down behavior only.
25-
34+
2635
## [1.0.0] - 2024-03-12
2736

2837
### Added

mppm/sync-play-mode.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Multiplayer Play Mode syncs the Main Editor and [Virtual Players](../virtual-pla
1212
| **Pause** | Pauses all activated Players (Main Editor and Virtual Players) |
1313
| **Step** | Performs a single-frame step for all activated Players (Main Editor and Virtual Players) |
1414

15-
In the toolbar of the **Play Mode** window, you can adjust the layout with the **Layout** dropdown. You can select and deselect the **Console**, **Game**, **Hierarchy**, **Inspector**, and **Scene**. Select **Apply** to implement your changes to the layout.
15+
You can change the layout of the **Multiplayer Play Mode** window with the **Layout** dropdown. To learn more, refer to [Change the layout of a Virtual Player](virtual-players-layout).
1616

1717
:::note
1818
If you enable Error Pause in the [Console](https://docs.unity3d.com/Manual/Console.html) toolbar of any Player, all Virtual Players pause when you call `Debug.LogError` from a script.

mppm/sys-req.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: System requirements and compatibility
66
The Multiplayer Play Mode package requires the following:
77

88
- Unity Editor version 2023.1 or later.
9-
- An active Project in Unity Hub.
9+
- An active Project in the Unity Hub.
1010

1111
## Compatibility
1212
Multiplayer Play Mode is compatible with the following multiplayer packages and services:

mppm/troubleshoot/debug-mppm.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ description: Learn how to test a player running in Multiplayer Play Mode
66

77
Use the Test Runner included in the [Unity Test Framework (UTF)](https://docs.unity3d.com/Packages/[email protected]/manual/index.html) to test players in a multiplayer project.
88

9+
:::note:
10+
Multiplayer Play Mode version 1.1.0 is compatible with Unity Editor versions 6000.0.3f1 or later. Multiplayer Play mode versions 1.0.0 and earlier are compatible with Unity version 2023.1 or later.
11+
:::
12+
913
## Test a player
1014
To open the Test Runner window go to **Window** > **General** > **Test Runner**.
1115

0 commit comments

Comments
 (0)