Skip to content

Commit 2459e08

Browse files
committed
Fix NetworkPoolManager.CreatePool so it adds created pool to Pools Dictionary
Fix NetworkPool.SpawnPooledObject condition to return pool object. Fix NetworkPool constructor so it adds object to the objects array for the pool. Eliminated two GetComponent calls from NetworkPool constructor.
1 parent e339a0b commit 2459e08

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

MLAPI/Data/NetworkPool.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ internal NetworkPool(int prefabId, uint size, ushort poolIndex)
1515
for (int i = 0; i < size; i++)
1616
{
1717
GameObject go = MonoBehaviour.Instantiate(NetworkingManager.Singleton.NetworkConfig.NetworkedPrefabs[prefabId].prefab, Vector3.zero, Quaternion.identity) as GameObject;
18-
go.GetComponent<NetworkedObject>().IsPooledObject = true;
19-
go.GetComponent<NetworkedObject>().PoolId = poolId;
20-
go.GetComponent<NetworkedObject>().Spawn();
18+
objects[i] = go.GetComponent<NetworkedObject>();
19+
objects[i].IsPooledObject = true;
20+
objects[i].PoolId = poolId;
21+
objects[i].Spawn();
2122
go.name = "Pool Id: " + poolId + " #" + i;
2223
go.SetActive(false);
2324
}
@@ -27,12 +28,13 @@ internal NetworkedObject SpawnObject(Vector3 position, Quaternion rotation)
2728
{
2829
for (int i = 0; i < objects.Length; i++)
2930
{
30-
if (objects[i].gameObject.activeInHierarchy)
31+
if (!objects[i].gameObject.activeInHierarchy)
3132
{
3233
GameObject go = objects[i].gameObject;
3334
go.transform.position = position;
3435
go.transform.rotation = rotation;
3536
go.SetActive(true);
37+
return objects[i];
3638
}
3739
}
3840
if (LogHelper.CurrentLogLevel <= LogLevel.Normal) LogHelper.LogWarning("The pool " + poolId + " has ran out of space");

MLAPI/NetworkingManagerComponents/Core/NetworkPoolManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public static void CreatePool(string poolName, int spawnablePrefabIndex, uint si
3030
return;
3131
}
3232
NetworkPool pool = new NetworkPool(spawnablePrefabIndex, size, PoolIndex);
33+
Pools.Add(PoolIndex, pool);
3334
PoolNamesToIndexes.Add(poolName, PoolIndex);
3435
PoolIndex++;
3536
}

0 commit comments

Comments
 (0)