Skip to content

Commit 05c64fa

Browse files
chore: remove unitytransport debug asserts [up-port] (#3226)
* update Replace the two places where Debug.Assert is used in UnityTransport to be DEBUG wrapped checks that log warnings as opposed to throwing asserts in order to avoid being considered a failed test run even if all tests have passed. * style Cleaning up message a bit. * test update to account for switching from a Debug.Assert to a Debug.LogWarning.
1 parent 2eee998 commit 05c64fa

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,13 @@ public override void DisconnectLocalClient()
12201220
/// <param name="clientId">The client to disconnect</param>
12211221
public override void DisconnectRemoteClient(ulong clientId)
12221222
{
1223-
Debug.Assert(m_State == State.Listening, "DisconnectRemoteClient should be called on a listening server");
1223+
#if DEBUG
1224+
if (m_State != State.Listening)
1225+
{
1226+
Debug.LogWarning($"{nameof(DisconnectRemoteClient)} should only be called on a listening server!");
1227+
return;
1228+
}
1229+
#endif
12241230

12251231
if (m_State == State.Listening)
12261232
{
@@ -1292,7 +1298,13 @@ public NetworkEndpoint GetEndpoint(ulong clientId)
12921298
/// <param name="networkManager">The NetworkManager that initialized and owns the transport</param>
12931299
public override void Initialize(NetworkManager networkManager = null)
12941300
{
1295-
Debug.Assert(sizeof(ulong) == UnsafeUtility.SizeOf<NetworkConnection>(), "Netcode connection id size does not match UTP connection id size");
1301+
#if DEBUG
1302+
if (sizeof(ulong) != UnsafeUtility.SizeOf<NetworkConnection>())
1303+
{
1304+
Debug.LogWarning($"Netcode connection id size {sizeof(ulong)} does not match UTP connection id size {UnsafeUtility.SizeOf<NetworkConnection>()}!");
1305+
return;
1306+
}
1307+
#endif
12961308

12971309
m_NetworkManager = networkManager;
12981310

com.unity.netcode.gameobjects/Tests/Runtime/Transports/UnityTransportTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ public IEnumerator DoesNotActAfterShutdown([Values] AfterShutdownAction afterShu
531531
{
532532
m_Server.DisconnectRemoteClient(m_Client1.ServerClientId);
533533

534-
LogAssert.Expect(LogType.Assert, "DisconnectRemoteClient should be called on a listening server");
534+
LogAssert.Expect(LogType.Warning, $"{nameof(UnityTransport.DisconnectRemoteClient)} should only be called on a listening server!");
535535
}
536536
else if (afterShutdownAction == AfterShutdownAction.DisconnectLocalClient)
537537
{

0 commit comments

Comments
 (0)