Skip to content

Commit f8c4d1b

Browse files
committed
Replace Debug by NeworkLog in NetworkObject
1 parent 7fc428b commit f8c4d1b

File tree

1 file changed

+48
-12
lines changed

1 file changed

+48
-12
lines changed

com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ internal void OnValidate()
297297
if (globalId.identifierType != k_SceneObjectType)
298298
{
299299
// This should never happen, but in the event it does throw and error.
300-
Debug.LogError($"[{gameObject.name}] is detected as an in-scene placed object but its identifier is of type {globalId.identifierType}! **Report this error**");
300+
NetworkLog.LogError($"[{gameObject.name}] is detected as an in-scene placed object but its identifier is of type {globalId.identifierType}! **Report this error**");
301301
}
302302

303303
// If this is a prefab instance, then we want to mark it as having been updated in order for the udpated GlobalObjectIdHash value to be saved.
@@ -1778,7 +1778,10 @@ internal void SpawnInternal(bool destroyWithScene, ulong ownerClientId, bool pla
17781778
{
17791779
if (NetworkManagerOwner.LocalClient == null || !NetworkManagerOwner.IsConnectedClient || !NetworkManagerOwner.ConnectionManager.LocalClient.IsApproved)
17801780
{
1781-
Debug.LogError($"Cannot spawn {name} until the client is fully connected to the session!");
1781+
if (NetworkManagerOwner.LogLevel <= LogLevel.Error)
1782+
{
1783+
NetworkLog.LogError($"Cannot spawn {name} until the client is fully connected to the session!");
1784+
}
17821785
return;
17831786
}
17841787
if (NetworkManagerOwner.NetworkConfig.EnableSceneManagement)
@@ -1856,7 +1859,11 @@ public static NetworkObject InstantiateAndSpawn(GameObject networkPrefab, Networ
18561859
var networkObject = networkPrefab.GetComponent<NetworkObject>();
18571860
if (networkObject == null)
18581861
{
1859-
Debug.LogError($"The {nameof(NetworkPrefab)} {networkPrefab.name} does not have a {nameof(NetworkObject)} component!");
1862+
if (networkManager.LogLevel <= LogLevel.Error)
1863+
{
1864+
NetworkLog.LogError($"The {nameof(NetworkPrefab)} {networkPrefab.name} does not have a {nameof(NetworkObject)} component!");
1865+
}
1866+
18601867
return null;
18611868
}
18621869
return networkObject.InstantiateAndSpawn(networkManager, ownerClientId, destroyWithScene, isPlayerObject, forceOverride, position, rotation);
@@ -1878,34 +1885,49 @@ public NetworkObject InstantiateAndSpawn(NetworkManager networkManager, ulong ow
18781885
{
18791886
if (networkManager == null)
18801887
{
1881-
Debug.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NetworkManagerNull]);
1888+
if (networkManager.LogLevel <= LogLevel.Error)
1889+
{
1890+
NetworkLog.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NetworkManagerNull]);
1891+
}
18821892
return null;
18831893
}
18841894

18851895
if (!networkManager.IsListening)
18861896
{
1887-
Debug.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NoActiveSession]);
1897+
if (networkManager.LogLevel <= LogLevel.Error)
1898+
{
1899+
NetworkLog.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NoActiveSession]);
1900+
}
18881901
return null;
18891902
}
18901903

18911904
ownerClientId = networkManager.DistributedAuthorityMode ? networkManager.LocalClientId : ownerClientId;
18921905
// We only need to check for authority when running in client-server mode
18931906
if (!networkManager.IsServer && !networkManager.DistributedAuthorityMode)
18941907
{
1895-
Debug.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NotAuthority]);
1908+
if (networkManager.LogLevel <= LogLevel.Error)
1909+
{
1910+
NetworkLog.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NotAuthority]);
1911+
}
18961912
return null;
18971913
}
18981914

18991915
if (networkManager.ShutdownInProgress)
19001916
{
1901-
Debug.LogWarning(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.InvokedWhenShuttingDown]);
1917+
if (networkManager.LogLevel <= LogLevel.Normal)
1918+
{
1919+
NetworkLog.LogWarning(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.InvokedWhenShuttingDown]);
1920+
}
19021921
return null;
19031922
}
19041923

19051924
// Verify it is actually a valid prefab
19061925
if (!networkManager.NetworkConfig.Prefabs.Contains(gameObject))
19071926
{
1908-
Debug.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NotRegisteredNetworkPrefab]);
1927+
if (networkManager.LogLevel <= LogLevel.Error)
1928+
{
1929+
NetworkLog.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NotRegisteredNetworkPrefab]);
1930+
}
19091931
return null;
19101932
}
19111933

@@ -2061,7 +2083,11 @@ internal void InvokeBehaviourOnOwnershipChanged(ulong originalOwnerClientId, ulo
20612083
{
20622084
if (!childBehaviour.gameObject.activeInHierarchy)
20632085
{
2064-
Debug.LogWarning($"[{name}] {childBehaviour.gameObject.name} is disabled! Netcode for GameObjects does not support disabled NetworkBehaviours! The {childBehaviour.GetType().Name} component was skipped during ownership assignment!");
2086+
if (NetworkManagerOwner.LogLevel <= LogLevel.Normal)
2087+
{
2088+
NetworkLog.LogWarning($"[{name}] {childBehaviour.gameObject.name} is disabled! Netcode for GameObjects does not support disabled NetworkBehaviours! The {childBehaviour.GetType().Name} component was skipped during ownership assignment!");
2089+
}
2090+
20652091
continue;
20662092
}
20672093

@@ -2080,7 +2106,10 @@ internal void InvokeOwnershipChanged(ulong previous, ulong next)
20802106
}
20812107
else
20822108
{
2083-
Debug.LogWarning($"[{name}] {ChildNetworkBehaviours[i].gameObject.name} is disabled! Netcode for GameObjects does not support disabled NetworkBehaviours! The {ChildNetworkBehaviours[i].GetType().Name} component was skipped during ownership assignment!");
2109+
if (NetworkManagerOwner.LogLevel <= LogLevel.Normal)
2110+
{
2111+
NetworkLog.LogWarning($"[{name}] {ChildNetworkBehaviours[i].gameObject.name} is disabled! Netcode for GameObjects does not support disabled NetworkBehaviours! The {ChildNetworkBehaviours[i].GetType().Name} component was skipped during ownership assignment!");
2112+
}
20842113
}
20852114
}
20862115
}
@@ -2597,7 +2626,10 @@ internal void InvokeBehaviourNetworkSpawn()
25972626
{
25982627
if (!childBehaviour.gameObject.activeInHierarchy)
25992628
{
2600-
Debug.LogWarning($"{GenerateDisabledNetworkBehaviourWarning(childBehaviour)}");
2629+
if (NetworkManager.LogLevel <= LogLevel.Normal)
2630+
{
2631+
NetworkLog.LogWarning($"{GenerateDisabledNetworkBehaviourWarning(childBehaviour)}");
2632+
}
26012633
continue;
26022634
}
26032635
childBehaviour.NetworkSpawn();
@@ -3356,7 +3388,11 @@ internal static NetworkObject Deserialize(in SerializedObject serializedObject,
33563388
// Ensure that the buffer is completely reset
33573389
if (reader.Position != endOfSynchronizationData)
33583390
{
3359-
Debug.LogWarning($"[Size mismatch] Expected: {endOfSynchronizationData} Currently At: {reader.Position}!");
3391+
if (networkManager.LogLevel <= LogLevel.Normal)
3392+
{
3393+
NetworkLog.LogWarning($"[Size mismatch] Expected: {endOfSynchronizationData} Currently At: {reader.Position}!");
3394+
}
3395+
33603396
reader.Seek(endOfSynchronizationData);
33613397
}
33623398
}

0 commit comments

Comments
 (0)