Skip to content

Commit 70473f0

Browse files
committed
Fix up the logging on AuthorityLocalSpawn
1 parent b3e7656 commit 70473f0

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,18 +1056,30 @@ internal NetworkObject CreateLocalNetworkObject(NetworkObject.SerializedObject s
10561056
/// </summary>
10571057
internal bool AuthorityLocalSpawn([NotNull] NetworkObject networkObject, ulong networkId, bool sceneObject, bool playerObject, ulong ownerClientId, bool destroyWithScene)
10581058
{
1059-
if (networkObject.IsSpawned || NetworkManager.SpawnManager.SpawnedObjects.ContainsKey(networkId))
1059+
if (networkObject.IsSpawned)
10601060
{
1061-
Debug.LogError($"{networkObject.name} is already spawned!");
1061+
if (NetworkManager.LogLevel <= LogLevel.Error)
1062+
{
1063+
NetworkLog.LogError($"Cannot process spawn of {networkObject.name} as it is already spawned!");
1064+
}
10621065
return false;
10631066
}
10641067

1065-
if (!sceneObject)
1068+
if (NetworkManager.SpawnManager.SpawnedObjects.TryGetValue(networkId, out var existingObj))
1069+
{
1070+
if (NetworkManager.LogLevel <= LogLevel.Error)
1071+
{
1072+
NetworkLog.LogError($"Cannot spawn {networkObject.name} with {nameof(networkId)}={networkId} as {existingObj.name} has already been spawned using this id!");
1073+
}
1074+
return false;
1075+
}
1076+
1077+
if (!sceneObject && NetworkManager.LogLevel <= LogLevel.Error)
10661078
{
10671079
var networkObjectChildren = networkObject.GetComponentsInChildren<NetworkObject>();
10681080
if (networkObjectChildren.Length > 1)
10691081
{
1070-
Debug.LogError("Spawning NetworkObjects with nested NetworkObjects is only supported for scene objects. Child NetworkObjects will not be spawned over the network!");
1082+
NetworkLog.LogWarning("Spawning NetworkObjects with nested NetworkObjects is only supported for scene objects. Child NetworkObjects will not be spawned over the network!");
10711083
}
10721084
}
10731085

@@ -1123,12 +1135,14 @@ internal bool AuthorityLocalSpawn([NotNull] NetworkObject networkObject, ulong n
11231135
NetworkLog.LogError($"Failed to spawn {nameof(NetworkObject)} {networkObject.name} with Hash {networkObject.GlobalObjectIdHash}.");
11241136
}
11251137

1138+
networkObject.ResetOnDespawn();
11261139
return false;
11271140
}
11281141

11291142
// When done spawning invoke post spawn
11301143
networkObject.InvokeBehaviourNetworkPostSpawn();
11311144

1145+
networkObject.IsSpawnAuthority = false;
11321146
return true;
11331147
}
11341148

0 commit comments

Comments
 (0)