Skip to content

Commit 7881f75

Browse files
Fix/migration cleanup lost changes (#417)
* fix: Add bug fixes wich where in master mlapi but didn't get migrated to develop. * fix: Add backk soft sync objects handling which was removed during migration * refactor: moved diffed scene object cleanup code to spawn manager Co-authored-by: Matt Walsh <matt.walsh@unity3d.com> Co-authored-by: mattwalsh-unity <69258106+mattwalsh-unity@users.noreply.github.com>
1 parent 51b9e2e commit 7881f75

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

com.unity.multiplayer.mlapi/Runtime/Configuration/NetworkConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public ulong GetConfig(bool cache = true)
336336
writer.WriteUInt16Packed(ProtocolVersion);
337337
writer.WriteString(MLAPIConstants.MLAPI_PROTOCOL_VERSION);
338338

339-
if (!AllowRuntimeSceneChanges)
339+
if (EnableSceneManagement && !AllowRuntimeSceneChanges)
340340
{
341341
for (int i = 0; i < RegisteredScenes.Count; i++)
342342
{

com.unity.multiplayer.mlapi/Runtime/Messaging/InternalMessageHandler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ void DelayedSpawnAction(Stream continuationStream)
344344
}
345345
}
346346

347+
SpawnManager.CleanDiffedSceneObjects();
348+
347349
NetworkingManager.Singleton.IsConnectedClient = true;
348350

349351
NetworkingManager.Singleton.InvokeOnClientConnectedCallback(NetworkingManager.Singleton.LocalClientId);

com.unity.multiplayer.mlapi/Runtime/Serialization/BitWriter.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ internal Stream GetStream()
5252
/// <param name="value">The object to write</param>
5353
public void WriteObjectPacked(object value)
5454
{
55-
if (value == null || value.GetType().IsNullable())
55+
// Check unitys custom null checks
56+
bool isNull = value == null || (value is UnityEngine.Object && ((UnityEngine.Object)value) == null);
57+
58+
if (isNull || value.GetType().IsNullable())
5659
{
57-
WriteBool(value == null);
60+
WriteBool(isNull);
5861

59-
if (value == null)
62+
if (isNull)
6063
{
6164
return;
6265
}

com.unity.multiplayer.mlapi/Runtime/Spawning/SpawnManager.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,25 @@ internal static void DestroySceneObjects()
596596
}
597597
}
598598

599+
internal static void CleanDiffedSceneObjects()
600+
{
601+
// Clean up the diffed scene objects. I.E scene objects that have been destroyed
602+
if (pendingSoftSyncObjects.Count > 0)
603+
{
604+
List<NetworkedObject> objectsToDestroy = new List<NetworkedObject>();
605+
606+
foreach (KeyValuePair<ulong, NetworkedObject> pair in pendingSoftSyncObjects)
607+
{
608+
objectsToDestroy.Add(pair.Value);
609+
}
610+
611+
for (int i = 0; i < objectsToDestroy.Count; i++)
612+
{
613+
MonoBehaviour.Destroy(objectsToDestroy[i].gameObject);
614+
}
615+
}
616+
}
617+
599618
internal static void ServerSpawnSceneObjectsOnStartSweep()
600619
{
601620
NetworkedObject[] networkedObjects = MonoBehaviour.FindObjectsOfType<NetworkedObject>();

0 commit comments

Comments
 (0)