Skip to content

Commit 9bb1c17

Browse files
Merge branch 'develop' into renovate/develop-recipeengine.modules.wrench-0.x
2 parents 293b8c1 + 3417c47 commit 9bb1c17

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ Additional documentation and release notes are available at [Multiplayer Documen
99
## [Unreleased]
1010

1111
### Added
12+
13+
- Added `NetworkManager.OnPreShutdown` which is called before the NetworkManager cleans up and shuts down. (#3358)
1214
- Added `FastBufferReader(ArraySegment<byte> buffer, Allocator copyAllocator)` constructor that uses the `ArraySegment.Offset` as the `FastBufferReader` offset and the `ArraySegment.Count` as the `FastBufferReader` length. (#3320)
1315
- Added `FastBufferReader(ArraySegment<byte> buffer, Allocator copyAllocator, int length = -1)` constructor that uses the `ArraySegment.Offset` as the `FastBufferReader` offset. (#3320)
1416

1517
### Fixed
1618

19+
- Fixed initial `NetworkTransform` spawn, ensure it uses world space. (#3361)
1720
- Fixed issue where `AnticipatedNetworkVariable` previous value returned by `AnticipatedNetworkVariable.OnAuthoritativeValueChanged` is updated correctly on the non-authoritative side. (#3322)
1821

1922
### Changed

com.unity.netcode.gameobjects/Components/NetworkTransform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2785,7 +2785,7 @@ public override void OnNetworkSpawn()
27852785

27862786
Initialize();
27872787

2788-
if (CanCommitToTransform && UseHalfFloatPrecision)
2788+
if (CanCommitToTransform)
27892789
{
27902790
SetState(GetSpaceRelativePosition(), GetSpaceRelativeRotation(), GetScale(), false);
27912791
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@ public struct ConnectionApprovalRequest
477477
/// </summary>
478478
public event Action OnClientStarted = null;
479479

480+
/// <summary>
481+
/// Subscribe to this event to get notifications before a <see cref="NetworkManager"/> instance is being destroyed.
482+
/// This is useful if you want to use the state of anything the NetworkManager cleans up during its shutdown.
483+
/// </summary>
484+
public event Action OnPreShutdown = null;
485+
480486
/// <summary>
481487
/// This callback is invoked once the local server is stopped.
482488
/// </summary>
@@ -1198,6 +1204,8 @@ internal void ShutdownInternal()
11981204
NetworkLog.LogInfo(nameof(ShutdownInternal));
11991205
}
12001206

1207+
OnPreShutdown?.Invoke();
1208+
12011209
this.UnregisterAllNetworkUpdates();
12021210

12031211
// Everything is shutdown in the order of their dependencies

com.unity.netcode.gameobjects/Tests/Runtime/NetworkManagerEventsTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,46 @@ public IEnumerator OnClientAndServerStartedCalledWhenHostStarts()
237237
Assert.AreEqual(2, callbacksInvoked, "either OnServerStarted or OnClientStarted wasn't invoked");
238238
}
239239

240+
[UnityTest]
241+
public IEnumerator OnPreShutdownCalledWhenShuttingDown()
242+
{
243+
bool preShutdownInvoked = false;
244+
bool shutdownInvoked = false;
245+
var gameObject = new GameObject(nameof(OnPreShutdownCalledWhenShuttingDown));
246+
m_ServerManager = gameObject.AddComponent<NetworkManager>();
247+
248+
// Set dummy transport that does nothing
249+
var transport = gameObject.AddComponent<DummyTransport>();
250+
m_ServerManager.NetworkConfig = new NetworkConfig() { NetworkTransport = transport };
251+
252+
Action onPreShutdown = () =>
253+
{
254+
preShutdownInvoked = true;
255+
Assert.IsFalse(shutdownInvoked, "OnPreShutdown was invoked after OnServerStopped");
256+
};
257+
258+
Action<bool> onServerStopped = (bool wasAlsoClient) =>
259+
{
260+
shutdownInvoked = true;
261+
Assert.IsTrue(preShutdownInvoked, "OnPreShutdown wasn't invoked before OnServerStopped");
262+
};
263+
264+
// Start server to cause initialization process
265+
Assert.True(m_ServerManager.StartServer());
266+
Assert.True(m_ServerManager.IsListening);
267+
268+
m_ServerManager.OnPreShutdown += onPreShutdown;
269+
m_ServerManager.OnServerStopped += onServerStopped;
270+
m_ServerManager.Shutdown();
271+
Object.DestroyImmediate(gameObject);
272+
273+
yield return WaitUntilManagerShutsdown();
274+
275+
Assert.False(m_ServerManager.IsListening);
276+
Assert.True(preShutdownInvoked, "OnPreShutdown wasn't invoked");
277+
Assert.True(shutdownInvoked, "OnServerStopped wasn't invoked");
278+
}
279+
240280
private IEnumerator WaitUntilManagerShutsdown()
241281
{
242282
/* Need two updates to actually shut down. First one to see the transport failing, which

pvpExceptions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,7 @@
928928
"Unity.Netcode.RuntimeTests.NetworkManagerEventsTests: IEnumerator OnServerStartedCalledWhenServerStarts(): undocumented",
929929
"Unity.Netcode.RuntimeTests.NetworkManagerEventsTests: IEnumerator OnClientStartedCalledWhenClientStarts(): undocumented",
930930
"Unity.Netcode.RuntimeTests.NetworkManagerEventsTests: IEnumerator OnClientAndServerStartedCalledWhenHostStarts(): undocumented",
931+
"Unity.Netcode.RuntimeTests.NetworkManagerEventsTests: IEnumerator OnPreShutdownCalledWhenShuttingDown(): undocumented",
931932
"Unity.Netcode.RuntimeTests.NetworkManagerEventsTests: IEnumerator Teardown(): undocumented",
932933
"Unity.Netcode.RuntimeTests.NetworkManagerSceneManagerTests: undocumented",
933934
"Unity.Netcode.RuntimeTests.NetworkManagerSceneManagerTests: void SceneManagerAssigned(): undocumented",

0 commit comments

Comments
 (0)