Skip to content

Commit 85eee7b

Browse files
committed
Ensured the OwnedObject's list is filled and kept up to date
1 parent b4d0303 commit 85eee7b

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

MLAPI/Data/NetworkPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal NetworkPool(int prefabIndex, uint size, ushort poolIndex)
1515
for (int i = 0; i < size; i++)
1616
{
1717
GameObject go = Object.Instantiate(NetworkingManager.singleton.SpawnablePrefabs[prefabIndex], Vector3.zero, Quaternion.identity);
18-
go.GetComponent<NetworkedObject>().IsPooledObject = true;
18+
go.GetComponent<NetworkedObject>().isPooledObject = true;
1919
go.GetComponent<NetworkedObject>().PoolId = poolId;
2020
go.GetComponent<NetworkedObject>().Spawn();
2121
go.name = "Pool Id: " + poolId + " #" + i;

MLAPI/MonoBehaviours/Core/NetworkedObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class NetworkedObject : MonoBehaviour
1515
public bool isPlayerObject = false;
1616
public bool ServerOnly = false;
1717
[HideInInspector]
18-
public bool IsPooledObject = false;
18+
public bool isPooledObject = false;
1919
[HideInInspector]
2020
public ushort PoolId;
2121
public bool isLocalPlayer

MLAPI/NetworkingManagerComponents/SpawnManager.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private static NetworkingManager netManager
3333
internal static void RemoveOwnership(uint netId)
3434
{
3535
NetworkedObject netObject = SpawnManager.spawnedObjects[netId];
36+
NetworkingManager.singleton.connectedClients[netObject.OwnerClientId].OwnedObjects.RemoveAll(x => x.NetworkId == netId);
3637
netObject.OwnerClientId = -2;
3738
using (MemoryStream stream = new MemoryStream(8))
3839
{
@@ -48,6 +49,8 @@ internal static void RemoveOwnership(uint netId)
4849
internal static void ChangeOwnership(uint netId, int clientId)
4950
{
5051
NetworkedObject netObject = SpawnManager.spawnedObjects[netId];
52+
NetworkingManager.singleton.connectedClients[netObject.OwnerClientId].OwnedObjects.RemoveAll(x => x.NetworkId == netId);
53+
NetworkingManager.singleton.connectedClients[clientId].OwnedObjects.Add(netObject);
5154
netObject.OwnerClientId = clientId;
5255
using (MemoryStream stream = new MemoryStream(8))
5356
{
@@ -114,6 +117,11 @@ internal static void OnDestroyObject(uint networkId, bool destroyGameObject)
114117
{
115118
if (!spawnedObjects.ContainsKey(networkId) || (netManager != null && !netManager.NetworkConfig.HandleObjectSpawning))
116119
return;
120+
if (spawnedObjects[networkId].OwnerClientId > -2 && !spawnedObjects[networkId].isPlayerObject)
121+
{
122+
//Someone owns it.
123+
NetworkingManager.singleton.connectedClients[spawnedObjects[networkId].OwnerClientId].OwnedObjects.RemoveAll(x => x.NetworkId == networkId);
124+
}
117125
GameObject go = spawnedObjects[networkId].gameObject;
118126
if (netManager != null && netManager.isServer)
119127
{
@@ -170,7 +178,10 @@ internal static void OnSpawnObject(NetworkedObject netObject, int? clientOwnerId
170178
spawnedObjects.Add(netId, netObject);
171179
netObject.isSpawned = true;
172180
if (clientOwnerId != null)
181+
{
173182
netObject.OwnerClientId = clientOwnerId.Value;
183+
NetworkingManager.singleton.connectedClients[clientOwnerId.Value].OwnedObjects.Add(netObject);
184+
}
174185
using (MemoryStream stream = new MemoryStream(13))
175186
{
176187
using (BinaryWriter writer = new BinaryWriter(stream))

0 commit comments

Comments
 (0)