Skip to content

Commit 691750d

Browse files
committed
Backport fixes
1 parent 70b4370 commit 691750d

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,14 @@ internal string ScenePathFromHash(uint sceneHash)
724724
}
725725
else
726726
{
727+
// In the event there is no scene associated with the scene event then just return "No Scene"
728+
// This can happen during unit tests when clients first connect and the only scene loaded is the
729+
// unit test scene (which is ignored by default) that results in a scene event that has no associated
730+
// scene. Under this specific special case, we just return "No Scene".
731+
if (sceneHash == 0)
732+
{
733+
return "No Scene";
734+
}
727735
throw new Exception($"Scene Hash {sceneHash} does not exist in the {nameof(HashToBuildIndex)} table! Verify that all scenes requiring" +
728736
$" server to client synchronization are in the scenes in build list.");
729737
}
@@ -1198,7 +1206,7 @@ public SceneEventProgressStatus UnloadScene(Scene scene)
11981206
sceneEventProgress.OnSceneEventCompleted = OnSceneUnloaded;
11991207
var sceneUnload = SceneManagerHandler.UnloadSceneAsync(scene, sceneEventProgress);
12001208
// Notify local server that a scene is going to be unloaded
1201-
InvokeSceneEvents(NetworkManager.ServerClientId, sceneEventData);
1209+
InvokeSceneEvents(NetworkManager.ServerClientId, sceneEventData, sceneUnload);
12021210

12031211
//Return the status
12041212
return sceneEventProgress.Status;
@@ -1254,8 +1262,11 @@ private void OnClientUnloadScene(uint sceneEventId)
12541262
throw new Exception($"Failed to remove server scene handle ({sceneEventData.SceneHandle}) or client scene handle({sceneHandle})! Happened during scene unload for {sceneName}.");
12551263
}
12561264

1265+
// The only scenes unloaded are scenes that were additively loaded
1266+
sceneEventData.LoadSceneMode = LoadSceneMode.Additive;
1267+
12571268
// Notify the local client that a scene is going to be unloaded
1258-
InvokeSceneEvents(NetworkManager.LocalClientId, sceneEventData);
1269+
InvokeSceneEvents(NetworkManager.LocalClientId, sceneEventData, sceneUnload);
12591270
}
12601271

12611272
/// <summary>
@@ -1933,7 +1944,7 @@ private void ClientLoadedSynchronization(uint sceneEventId)
19331944
EndSceneEvent(responseSceneEventData.SceneEventId);
19341945

19351946
// Send notification to local client that the scene has finished loading
1936-
InvokeSceneEvents(NetworkManager.LocalClientId, responseSceneEventData);
1947+
InvokeSceneEvents(NetworkManager.LocalClientId, responseSceneEventData, scene: nextScene);
19371948

19381949
// Check to see if we still have scenes to load and synchronize with
19391950
HandleClientSceneEvent(sceneEventId);

com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTest.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,9 +1760,14 @@ public NetcodeIntegrationTest(HostOrServer hostOrServer)
17601760
protected void AssertOnTimeout(string timeOutErrorMessage, TimeoutHelper assignedTimeoutHelper = null)
17611761
{
17621762
var timeoutHelper = assignedTimeoutHelper ?? s_GlobalTimeoutHelper;
1763-
var internalError = m_InternalErrorLog.Length > 0 ? $"{timeOutErrorMessage}\n{m_InternalErrorLog}" : timeOutErrorMessage;
1764-
Assert.False(timeoutHelper.TimedOut, internalError);
1765-
m_InternalErrorLog.Clear();
1763+
if (m_InternalErrorLog.Length > 0)
1764+
{
1765+
Assert.False(timeoutHelper.TimedOut, $"{timeOutErrorMessage}\n{m_InternalErrorLog}");
1766+
m_InternalErrorLog.Clear();
1767+
return;
1768+
}
1769+
1770+
Assert.False(timeoutHelper.TimedOut, timeOutErrorMessage);
17661771
}
17671772

17681773
private void UnloadRemainingScenes()

0 commit comments

Comments
 (0)