Skip to content

Commit 8576e33

Browse files
test - update
Re-factoring this test to align with the previously committed fix.
1 parent 79f9702 commit 8576e33

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System.Collections;
2+
using System.Linq;
3+
using System.Text.RegularExpressions;
24
using NUnit.Framework;
35
using Unity.Netcode.Components;
46
using Unity.Netcode.TestHelpers.Runtime;
@@ -71,8 +73,8 @@ protected override void OnNewClientCreated(NetworkManager networkManager)
7173
/// is not deleted until a later time would cause an exception due to the
7274
/// NetworkBehaviour not being removed from the NetworkObject.ChildNetworkBehaviours
7375
/// list.
74-
/// - That when a child GameObject is deleted/disabled or a NetworkBehaviour is disabled
75-
/// a message is logged and the NetworkObject still can be spawned and synchronized.
76+
/// - When a NetworkBehaviour is disabled but the associated GameObject is enabled,
77+
/// the object spawns without any issues.
7678
/// </summary>
7779
[UnityTest]
7880
public IEnumerator ValidatedDisableddNetworkBehaviourWarning([Values] bool disableGameObject)
@@ -101,11 +103,18 @@ public IEnumerator ValidatedDisableddNetworkBehaviourWarning([Values] bool disab
101103
// Now create an instance of the prefab
102104
var instance = Object.Instantiate(m_PrefabToSpawn);
103105
var instanceNetworkObject = instance.GetComponent<NetworkObject>();
104-
// Generate the expected warning message
105-
var expectedWarning = instanceNetworkObject.GenerateDisabledNetworkBehaviourWarning(instanceNetworkObject.GetComponentInChildren<NetworkTransform>(true));
106+
// When the GameObject is disabled, check for the warning.
107+
if (disableGameObject)
108+
{
109+
// Generate the expected warning message
110+
var expectedWarning = instanceNetworkObject.GenerateDisabledNetworkBehaviourWarning(instanceNetworkObject.GetComponentInChildren<NetworkTransform>(true));
111+
var expectedSplit = expectedWarning.Split(']');
112+
var expectedWarningBody = expectedSplit.Last();
113+
LogAssert.Expect(LogType.Warning, new Regex($".*{expectedWarningBody}*."));
114+
}
115+
106116
// Spawn the instance
107117
SpawnObjectInstance(instanceNetworkObject, m_ServerNetworkManager);
108-
LogAssert.Expect(LogType.Warning, $"{expectedWarning}");
109118
// Asure the connected client spawned the object first
110119
yield return WaitForSpawnedOnAllOrTimeOut(instanceNetworkObject);
111120
AssertOnTimeout($"Not all clients spawned {instanceNetworkObject.name}!");

0 commit comments

Comments
 (0)