Skip to content

Commit 2480daf

Browse files
Merge branch 'develop' into fix/test-roject-runtimetests-standalone-testrunner-build
2 parents bee18d3 + 096f614 commit 2480daf

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2323
- Fixed The NetworkConfig's checksum hash includes the NetworkTick so that clients with a different tickrate than the server are identified and not allowed to connect. (#1513)
2424
- Fixed OwnedObjects not being properly modified when using ChangeOwnership. (#1572)
2525
- Fixed When the LogLevel is set to developer NetworkBehaviour generates warning messages when it should not (#1631)
26+
- Fixed client-side exception from being thrown in NetworkSceneManager when migrating NetworkObjects to or from the DDOL scene. (#1633)
2627

2728
### Changed
2829

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,11 @@ internal void MoveObjectsToDontDestroyOnLoad()
18021802
var objectsToKeep = new HashSet<NetworkObject>(m_NetworkManager.SpawnManager.SpawnedObjectsList);
18031803
foreach (var sobj in objectsToKeep)
18041804
{
1805+
if (sobj == null)
1806+
{
1807+
continue;
1808+
}
1809+
18051810
if (!sobj.DestroyWithScene || sobj.gameObject.scene == DontDestroyOnLoadScene)
18061811
{
18071812
// Only move dynamically spawned network objects with no parent as child objects will follow
@@ -1877,6 +1882,10 @@ internal void MoveObjectsFromDontDestroyOnLoadToScene(Scene scene)
18771882

18781883
foreach (var sobj in objectsToKeep)
18791884
{
1885+
if (sobj == null)
1886+
{
1887+
continue;
1888+
}
18801889
// If it is in the DDOL then
18811890
if (sobj.gameObject.scene == DontDestroyOnLoadScene)
18821891
{

testproject/Assets/Tests/Manual/Scripts/NetworkPrefabPool.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ public override void OnNetworkDespawn()
238238

239239
foreach (var obj in m_ObjectPool)
240240
{
241+
if (obj == null)
242+
{
243+
continue;
244+
}
241245
var networkObject = obj.GetComponent<NetworkObject>();
242246
var genericBehaviour = obj.GetComponent<GenericNetworkObjectBehaviour>();
243247
if (networkObject.IsSpawned)

testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,7 @@ private void Server_OnLoad(ulong clientId, string sceneName, LoadSceneMode loadS
919919
ClientProcessedNotification(clientId, SceneEventType.Load, true);
920920
}
921921
#endregion
922+
922923
}
923924

924925
/// <summary>
@@ -1103,4 +1104,66 @@ public void SetInScene(bool isInScene)
11031104

11041105
}
11051106

1107+
1108+
public class NetworkSceneManagerFixValidationTests : BaseMultiInstanceTest
1109+
{
1110+
protected override int NbClients => 0;
1111+
1112+
public override IEnumerator Setup()
1113+
{
1114+
m_BypassStartAndWaitForClients = true;
1115+
return base.Setup();
1116+
}
1117+
1118+
/// <summary>
1119+
/// This validation test verifies that the NetworkSceneManager will not crash if
1120+
/// the SpawnManager.SpawnedObjectsList contains destroyed and invalid NetworkObjects.
1121+
/// </summary>
1122+
[Test]
1123+
public void DDOLPopulateWithNullNetworkObjectsValidation([Values] bool useHost)
1124+
{
1125+
var gameObject = new GameObject();
1126+
var networkObject = gameObject.AddComponent<NetworkObject>();
1127+
MultiInstanceHelpers.MakeNetworkObjectTestPrefab(networkObject);
1128+
1129+
m_ServerNetworkManager.NetworkConfig.NetworkPrefabs.Add(new NetworkPrefab() { Prefab = gameObject });
1130+
1131+
foreach (var clientNetworkManager in m_ClientNetworkManagers)
1132+
{
1133+
clientNetworkManager.NetworkConfig.NetworkPrefabs.Add(new NetworkPrefab() { Prefab = gameObject });
1134+
}
1135+
1136+
// Start the host and clients
1137+
if (!MultiInstanceHelpers.Start(useHost, m_ServerNetworkManager, m_ClientNetworkManagers))
1138+
{
1139+
Debug.LogError("Failed to start instances");
1140+
Assert.Fail("Failed to start instances");
1141+
}
1142+
1143+
// Spawn some NetworkObjects
1144+
var spawnedNetworkObjects = new List<GameObject>();
1145+
for (int i = 0; i < 10; i++)
1146+
{
1147+
var instance = Object.Instantiate(gameObject);
1148+
var instanceNetworkObject = instance.GetComponent<NetworkObject>();
1149+
instanceNetworkObject.NetworkManagerOwner = m_ServerNetworkManager;
1150+
instanceNetworkObject.Spawn();
1151+
spawnedNetworkObjects.Add(instance);
1152+
}
1153+
1154+
// Add a bogus entry to the SpawnManager
1155+
m_ServerNetworkManager.SpawnManager.SpawnedObjectsList.Add(null);
1156+
1157+
// Verify moving all NetworkObjects into the DDOL when some might be invalid will not crash
1158+
m_ServerNetworkManager.SceneManager.MoveObjectsToDontDestroyOnLoad();
1159+
1160+
// Verify moving all NetworkObjects from DDOL back into the active scene will not crash even if some are invalid
1161+
m_ServerNetworkManager.SceneManager.MoveObjectsFromDontDestroyOnLoadToScene(SceneManager.GetActiveScene());
1162+
1163+
// Now remove the invalid object
1164+
m_ServerNetworkManager.SpawnManager.SpawnedObjectsList.Remove(null);
1165+
1166+
// As long as there are no exceptions this test passes
1167+
}
1168+
}
11061169
}

0 commit comments

Comments
 (0)