Skip to content

Commit 9abffa9

Browse files
committed
Merge branch 'develop-2.0.0' into chore/remove-spawn-state-exceptions-network-object
2 parents b366562 + 454d04f commit 9abffa9

File tree

60 files changed

+760
-316
lines changed

Some content is hidden

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

60 files changed

+760
-316
lines changed

.yamato/project.metafile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
small_agent_platform:
2525
- name: ubuntu
2626
type: Unity::VM
27-
image: package-ci/ubuntu-22.04:v4.81.0
27+
image: package-ci/ubuntu-22.04:v4.82.0
2828
flavor: b1.small
2929

3030

@@ -39,13 +39,13 @@ test_platforms:
3939
default:
4040
- name: ubuntu
4141
type: Unity::VM
42-
image: package-ci/ubuntu-22.04:v4.81.0
42+
image: package-ci/ubuntu-22.04:v4.82.0
4343
flavor: b1.large
4444
standalone: StandaloneLinux64
4545
desktop:
4646
- name: ubuntu
4747
type: Unity::VM
48-
image: package-ci/ubuntu-22.04:v4.81.0
48+
image: package-ci/ubuntu-22.04:v4.82.0
4949
flavor: b1.large
5050
smaller_flavor: b1.medium
5151
larger_flavor: b1.xlarge

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ Additional documentation and release notes are available at [Multiplayer Documen
1010

1111
### Added
1212

13-
- Added stricter checks on `InSpawned` within `NetworkObject`. (#3831)
14-
- Added a new `InvalidOperation` status to `OwnershipRequestStatus`. (#3831)
13+
- The `NetworkMetricsPipelineStage` for Unity Transport is now part of the public API. This allows using it in custom implementations of `INetworkStreamDriverConstructor` that want to maintain compatibility with the multiplayer tools package. (#3853)
1514

1615
### Changed
1716

18-
- Ensure logs in `NetworkObject` log the `NetworkObject.name` wherever possible. (#3831)
19-
- Improved performance of NetworkBehaviour ILPostProcessor by omitting unnecessary type and assembly resolutions. (#3827)
20-
- Improve performance of `NetworkObject`. (#3820, #3831)
21-
- If the Unity Transport Disconnect Timeout is set to 0 in the Editor, the timeout will be entirely disabled. (#3810)
17+
- Updating usage of deprecated `FindObjectsByType(FindObjectsSortMode)` and enum `FindObjectSortMode` in 6000.4 and 6000.5. (#3857)
2218

2319
### Deprecated
2420

@@ -28,18 +24,38 @@ Additional documentation and release notes are available at [Multiplayer Documen
2824

2925
### Fixed
3026

31-
- Duplicate transport connection events for the same connection will now do nothing. (#3863)
32-
- Fixed memory leak in `NetworkAnimator` on clients where `RpcTarget` groups were not being properly disposed due to incorrect type casting of `ProxyRpcTargetGroup` to `RpcTargetGroup`.
33-
- Fixed issue when using a client-server topology where a `NetworkList` with owner write permissions was resetting sent time and dirty flags after having been spawned on owning clients that were not the spawn authority. (#3850)
34-
- Fixed an integer overflow that occurred when configuring a large disconnect timeout with Unity Transport. (#3810)
35-
27+
- Fixed issue where `NetworkVariable` was not properly synchronizing to changes made by the spawn and write authority during `OnNetworkSpawn` and `OnNetworkPostSpawn`. (#3878)
28+
- Fixed issue where `NetworkManager` was not cleaning itself up if an exception was thrown while starting. (#3864)
29+
- Prevented a `NullReferenceException` in `UnityTransport` when using a custom `INetworkStreamDriverConstructor` that doesn't use all the default pipelines and the multiplayer tools package is installed. (#3853)
3630

3731
### Security
3832

3933

4034
### Obsolete
4135

4236

37+
## [2.9.0] - 2026-02-01
38+
39+
### Added
40+
41+
- Added stricter checks on `InSpawned` within `NetworkObject`. (#3831)
42+
- Added a new `InvalidOperation` status to `OwnershipRequestStatus`. (#3831)
43+
44+
### Changed
45+
46+
- Ensure logs in `NetworkObject` log the `NetworkObject.name` wherever possible. (#3831)
47+
- Improved performance of NetworkBehaviour ILPostProcessor by omitting unnecessary type and assembly resolutions. (#3827)
48+
- Improve performance of `NetworkObject`. (#3820, #3831)
49+
- If the Unity Transport Disconnect Timeout is set to 0 in the Editor, the timeout will be entirely disabled. (#3810)
50+
51+
### Fixed
52+
53+
- Duplicate transport connection events for the same connection will now do nothing. (#3863)
54+
- Fixed memory leak in `NetworkAnimator` on clients where `RpcTarget` groups were not being properly disposed due to incorrect type casting of `ProxyRpcTargetGroup` to `RpcTargetGroup`.
55+
- Fixed issue when using a client-server topology where a `NetworkList` with owner write permissions was resetting sent time and dirty flags after having been spawned on owning clients that were not the spawn authority. (#3850)
56+
- Fixed an integer overflow that occurred when configuring a large disconnect timeout with Unity Transport. (#3810)
57+
58+
4359
## [2.8.0] - 2025-12-15
4460

4561
### Added

com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private static void ScenesInBuildActiveSceneCheck()
9292
var activeScene = SceneManager.GetActiveScene();
9393
var isSceneInBuildSettings = scenesList.Count((c) => c.path == activeScene.path) == 1;
9494
#if UNITY_2023_1_OR_NEWER
95-
var networkManager = Object.FindFirstObjectByType<NetworkManager>();
95+
var networkManager = Object.FindAnyObjectByType<NetworkManager>();
9696
#else
9797
var networkManager = Object.FindObjectOfType<NetworkManager>();
9898
#endif

com.unity.netcode.gameobjects/Runtime/Components/Helpers/AttachableBehaviour.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public override void OnNetworkPreDespawn()
282282
{
283283
ForceDetach();
284284
}
285-
base.OnNetworkDespawn();
285+
base.OnNetworkPreDespawn();
286286
}
287287

288288
/// <summary>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#if NGO_FINDOBJECTS_NOSORTING
2+
using System;
3+
#endif
4+
using System.Runtime.CompilerServices;
5+
using Object = UnityEngine.Object;
6+
7+
namespace Unity.Netcode
8+
{
9+
/// <summary>
10+
/// Helper class to handle the variations of FindObjectsByType.
11+
/// </summary>
12+
/// <remarks>
13+
/// It is intentional that we do not include the UnityEngine namespace in order to avoid
14+
/// over-complicatd define wrapping between versions that do or don't support FindObjectsSortMode.
15+
/// </remarks>
16+
internal static class FindObjects
17+
{
18+
/// <summary>
19+
/// Replaces <see cref="Object.FindObjectsByType"/> to have one place where these changes are applied.
20+
/// </summary>
21+
/// <typeparam name="T"></typeparam>
22+
/// <param name="includeInactive">When true, inactive objects will be included.</param>
23+
/// <param name="orderByIdentifier">When true, the array returned will be sorted by identifier.</param>
24+
/// <returns>Resulst as an <see cref="Array"/> of type T</returns>
25+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
26+
public static T[] ByType<T>(bool includeInactive = false, bool orderByIdentifier = false) where T : Object
27+
{
28+
var inactive = includeInactive ? UnityEngine.FindObjectsInactive.Include : UnityEngine.FindObjectsInactive.Exclude;
29+
#if NGO_FINDOBJECTS_NOSORTING
30+
var results = Object.FindObjectsByType<T>(inactive);
31+
if (orderByIdentifier)
32+
{
33+
Array.Sort(results, (a, b) => a.GetEntityId().CompareTo(b.GetEntityId()));
34+
}
35+
#else
36+
var results = Object.FindObjectsByType<T>(inactive, orderByIdentifier ? UnityEngine.FindObjectsSortMode.InstanceID : UnityEngine.FindObjectsSortMode.None);
37+
#endif
38+
return results;
39+
}
40+
}
41+
}

com.unity.netcode.gameobjects/Runtime/Core/FindObjects.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ internal void NetworkPostSpawn()
838838
// all spawn related methods have been invoked.
839839
for (int i = 0; i < NetworkVariableFields.Count; i++)
840840
{
841-
NetworkVariableFields[i].OnSpawned();
841+
NetworkVariableFields[i].InternalOnSpawned();
842842
}
843843
}
844844

@@ -891,7 +891,7 @@ internal void InternalOnNetworkPreDespawn()
891891
// all spawn related methods have been invoked.
892892
for (int i = 0; i < NetworkVariableFields.Count; i++)
893893
{
894-
NetworkVariableFields[i].OnPreDespawn();
894+
NetworkVariableFields[i].InternalOnPreDespawn();
895895
}
896896
}
897897

com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,17 @@ public bool StartServer()
13231323
}
13241324
ConnectionManager.LocalClient.ClientId = ServerClientId;
13251325

1326-
Initialize(true);
1326+
try
1327+
{
1328+
Initialize(true);
1329+
}
1330+
catch (Exception ex)
1331+
{
1332+
Debug.LogException(ex);
1333+
// Always shutdown to assure everything is cleaned up
1334+
ShutdownInternal();
1335+
return false;
1336+
}
13271337

13281338
try
13291339
{
@@ -1342,11 +1352,12 @@ public bool StartServer()
13421352

13431353
ConnectionManager.TransportFailureEventHandler(true);
13441354
}
1345-
catch (Exception)
1355+
catch (Exception ex)
13461356
{
1347-
ConnectionManager.LocalClient.SetRole(false, false);
1357+
Debug.LogException(ex);
1358+
// Always shutdown to assure everything is cleaned up
1359+
ShutdownInternal();
13481360
IsListening = false;
1349-
throw;
13501361
}
13511362

13521363
return IsListening;
@@ -1373,7 +1384,16 @@ public bool StartClient()
13731384
return false;
13741385
}
13751386

1376-
Initialize(false);
1387+
try
1388+
{
1389+
Initialize(false);
1390+
}
1391+
catch (Exception ex)
1392+
{
1393+
Debug.LogException(ex);
1394+
ShutdownInternal();
1395+
return false;
1396+
}
13771397

13781398
try
13791399
{
@@ -1391,7 +1411,7 @@ public bool StartClient()
13911411
catch (Exception ex)
13921412
{
13931413
Debug.LogException(ex);
1394-
ConnectionManager.LocalClient.SetRole(false, false);
1414+
ShutdownInternal();
13951415
IsListening = false;
13961416
}
13971417

@@ -1419,7 +1439,18 @@ public bool StartHost()
14191439
return false;
14201440
}
14211441

1422-
Initialize(true);
1442+
try
1443+
{
1444+
Initialize(true);
1445+
}
1446+
catch (Exception ex)
1447+
{
1448+
Debug.LogException(ex);
1449+
// Always shutdown to assure everything is cleaned up
1450+
ShutdownInternal();
1451+
return false;
1452+
}
1453+
14231454
try
14241455
{
14251456
IsListening = NetworkConfig.NetworkTransport.StartServer();
@@ -1437,7 +1468,8 @@ public bool StartHost()
14371468
catch (Exception ex)
14381469
{
14391470
Debug.LogException(ex);
1440-
ConnectionManager.LocalClient.SetRole(false, false);
1471+
// Always shutdown to assure everything is cleaned up
1472+
ShutdownInternal();
14411473
IsListening = false;
14421474
}
14431475

com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,6 @@ public NetworkList(IEnumerable<T> values = default,
5858
Dispose();
5959
}
6060

61-
internal override void OnSpawned()
62-
{
63-
// If the NetworkList is:
64-
// - Dirty
65-
// - State updates can be sent:
66-
// -- The instance has write permissions.
67-
// -- The last sent time plus the max send time period is less than the current time.
68-
// - User script has modified the list during spawn.
69-
// - This instance is on the spawn authority side.
70-
// When the NetworkObject is finished spawning (on the same frame), go ahead and reset
71-
// the dirty related properties and last sent time to prevent duplicate entries from
72-
// being sent (i.e. CreateObjectMessage will contain the changes so we don't need to
73-
// send a proceeding NetworkVariableDeltaMessage).
74-
if (IsDirty() && CanSend() && m_NetworkObject.IsSpawnAuthority)
75-
{
76-
UpdateLastSentTime();
77-
ResetDirty();
78-
SetDirty(false);
79-
}
80-
base.OnSpawned();
81-
}
82-
8361
/// <inheritdoc cref="NetworkVariable{T}.ResetDirty"/>
8462
public override void ResetDirty()
8563
{

com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,27 +140,37 @@ public void Initialize(NetworkBehaviour networkBehaviour)
140140
}
141141
}
142142

143-
/// TODO-API: After further vetting and alignment on these, we might make them part of the public API.
144-
/// Could actually be like an interface that gets automatically registered for these kinds of notifications
145-
/// without having to be a NetworkBehaviour.
146-
#region OnSpawn and OnPreDespawn (ETC)
147-
148143
/// <summary>
149144
/// Invoked after the associated <see cref="NetworkBehaviour.OnNetworkPostSpawn"/> has been invoked.
150145
/// </summary>
151-
internal virtual void OnSpawned()
146+
internal void InternalOnSpawned()
152147
{
153-
148+
// If the NetworkVariableBase derived class is:
149+
// - On the spawn authority side.
150+
// - Dirty.
151+
// - State updates can be sent:
152+
// -- The instance has write permissions.
153+
// -- The last sent time plus the max send time period is less than the current time.
154+
// - User script has modified the list during spawn.
155+
// When the NetworkObject is finished spawning (on the same frame), go ahead and reset
156+
// the dirty related properties and last sent time to prevent duplicate updates from
157+
// being sent (i.e. CreateObjectMessage will contain the changes so we don't need to
158+
// send a proceeding NetworkVariableDeltaMessage).
159+
if (m_NetworkObject.IsSpawnAuthority && IsDirty() && CanWrite() && CanSend())
160+
{
161+
UpdateLastSentTime();
162+
ResetDirty();
163+
SetDirty(false);
164+
}
154165
}
155166

156167
/// <summary>
157168
/// Invoked after the associated <see cref="NetworkBehaviour.OnNetworkPreDespawn"/> has been invoked.
158169
/// </summary>
159-
internal virtual void OnPreDespawn()
170+
internal void InternalOnPreDespawn()
160171
{
161172

162173
}
163-
#endregion
164174

165175
/// <summary>
166176
/// Deinitialize is invoked when a NetworkObject is despawned.

0 commit comments

Comments
 (0)