Skip to content

Commit 0fd34c8

Browse files
committed
Simplify finding targetOwner onClientDisconnect
1 parent 1a82660 commit 0fd34c8

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,27 +1211,24 @@ internal void OnClientDisconnectFromServer(ulong clientId)
12111211
}
12121212

12131213
var targetOwner = NetworkManager.ServerClientId;
1214-
if (predictedClientCount > 1)
1214+
// Cycle through the full count of clients to find
1215+
// the next viable owner. If none are found, then
1216+
// the DAHost defaults to the owner.
1217+
for (int j = 0; j < remainingClients.Count; j++)
12151218
{
12161219
clientCounter++;
1217-
clientCounter %= predictedClientCount;
1218-
targetOwner = remainingClients[clientCounter].ClientId;
1220+
clientCounter = clientCounter % predictedClientCount;
1221+
if (ownedObject.Observers.Contains(remainingClients[clientCounter].ClientId))
1222+
{
1223+
targetOwner = remainingClients[clientCounter].ClientId;
1224+
break;
1225+
}
12191226
}
12201227
if (EnableDistributeLogging)
12211228
{
12221229
Debug.Log($"[Disconnected][Client-{clientId}][NetworkObjectId-{ownedObject.NetworkObjectId} Distributed to Client-{targetOwner}");
12231230
}
12241231

1225-
if (!ownedObject.Observers.Contains(targetOwner))
1226-
{
1227-
targetOwner = NetworkManager.ServerClientId;
1228-
}
1229-
1230-
if (!ownedObject.Observers.Contains(targetOwner))
1231-
{
1232-
targetOwner = ownedObject.Observers.First();
1233-
}
1234-
12351232
NetworkManager.SpawnManager.ChangeOwnership(ownedObject, targetOwner, true);
12361233

12371234
// Ownership gets passed down to all children that have the same owner.

0 commit comments

Comments
 (0)