Skip to content

Commit

Permalink
Merge develop into feat/per_client_MTU
Browse files Browse the repository at this point in the history
  • Loading branch information
netcode-ci-service authored Aug 30, 2023
2 parents 3e3b61c + f890d7e commit 748cfea
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Fixed

- Fixed issue where `SpawnWithObservers` was not being honored when `NetworkConfig.EnableSceneManagement` was disabled. (#2682)
- Fixed issue where `NetworkAnimator` was not internally tracking changes to layer weights which prevented proper layer weight synchronization back to the original layer weight value. (#2674)
- Fixed "writing past the end of the buffer" error when calling ResetDirty() on managed network variables that are larger than 256 bytes when serialized. (#2670)
- Fixed issue where generation of the `DefaultNetworkPrefabs` asset was not enabled by default. (#2662)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public void Serialize(FastBufferWriter writer, int targetVersion)
BytePacker.WriteValueBitPacked(writer, NetworkTick);

uint sceneObjectCount = 0;

// When SpawnedObjectsList is not null then scene management is disabled. Provide a list of
// all observed and spawned NetworkObjects that the approved client needs to synchronize.
if (SpawnedObjectsList != null)
{
var pos = writer.Position;
Expand All @@ -45,7 +48,7 @@ public void Serialize(FastBufferWriter writer, int targetVersion)
// Serialize NetworkVariable data
foreach (var sobj in SpawnedObjectsList)
{
if (sobj.CheckObjectVisibility == null || sobj.CheckObjectVisibility(OwnerClientId))
if (sobj.SpawnWithObservers && (sobj.CheckObjectVisibility == null || sobj.CheckObjectVisibility(OwnerClientId)))
{
sobj.Observers.Add(OwnerClientId);
var sceneObject = sobj.GetMessageSceneObject(OwnerClientId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected override void OnNewClientCreated(NetworkManager networkManager)
networkManager.NetworkConfig.Prefabs.Add(networkPrefab);
}
}
networkManager.NetworkConfig.EnableSceneManagement = m_ServerNetworkManager.NetworkConfig.EnableSceneManagement;
base.OnNewClientCreated(networkManager);
}

Expand All @@ -82,8 +83,46 @@ protected override void OnNewClientCreated(NetworkManager networkManager)
/// </summary>
/// <param name="observerTestTypes">whether to spawn with or without observers</param>
[UnityTest]
public IEnumerator ObserverSpawnTests([Values] ObserverTestTypes observerTestTypes)
public IEnumerator ObserverSpawnTests([Values] ObserverTestTypes observerTestTypes, [Values] bool sceneManagement)
{
if (!sceneManagement)
{
// Disable prefabs to prevent them from being destroyed
foreach (var networkPrefab in m_ServerNetworkManager.NetworkConfig.Prefabs.Prefabs)
{
networkPrefab.Prefab.SetActive(false);
}

// Shutdown and clean up the current client NetworkManager instances
foreach (var networkManager in m_ClientNetworkManagers)
{
m_PlayerNetworkObjects[networkManager.LocalClientId].Clear();
m_PlayerNetworkObjects.Remove(networkManager.LocalClientId);
yield return StopOneClient(networkManager, true);
}

// Shutdown and clean up the server NetworkManager instance
m_PlayerNetworkObjects[m_ServerNetworkManager.LocalClientId].Clear();
yield return StopOneClient(m_ServerNetworkManager);

// Set the prefabs to active again
foreach (var networkPrefab in m_ServerNetworkManager.NetworkConfig.Prefabs.Prefabs)
{
networkPrefab.Prefab.SetActive(true);
}

// Disable scene management and start the host
m_ServerNetworkManager.NetworkConfig.EnableSceneManagement = false;
m_ServerNetworkManager.StartHost();
yield return s_DefaultWaitForTick;

// Create 2 new clients and connect them
for (int i = 0; i < NumberOfClients; i++)
{
yield return CreateAndStartNewClient();
}
}

m_ObserverTestType = observerTestTypes;
var prefabNetworkObject = m_ObserverPrefab.GetComponent<NetworkObject>();
prefabNetworkObject.SpawnWithObservers = observerTestTypes == ObserverTestTypes.WithObservers;
Expand Down Expand Up @@ -129,6 +168,7 @@ public IEnumerator ObserverSpawnTests([Values] ObserverTestTypes observerTestTyp
AssertOnTimeout($"{k_WithObserversError} {k_ObserverTestObjName} object!");
}
}

/// <summary>
/// Tests that instantiating a <see cref="NetworkObject"/> and destroying without spawning it
/// does not run <see cref="NetworkBehaviour.OnNetworkSpawn"/> or <see cref="NetworkBehaviour.OnNetworkSpawn"/>.
Expand Down

0 comments on commit 748cfea

Please sign in to comment.