You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NetworkObjectPool feature parity with the version in the Unity Multiplayer Samples Boss Room sample project (#176)
* Updating the NetworkObjectPool to have feature parity with the version in the Multiplayer Samples BossRoom project (it's now a NetworkBehaviour instead of a MonoBehaviour, uses the NetworkManager.Singleton, initializes the pool in OnNetworkSpawn, and it's a singleton)
* feature parity with the NetworkObjectPool in the Unity Multiplayer Samples Co-op Boss Room sample project.
Copy file name to clipboardExpand all lines: com.community.netcode.extensions/Runtime/NetworkObjectPool/NetworkObjectPool.cs
+83-19Lines changed: 83 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,16 @@
7
7
8
8
namespaceNetcode.Extensions
9
9
{
10
-
publicclassNetworkObjectPool:MonoBehaviour
10
+
/// <summary>
11
+
/// Object Pool for networked objects, used for controlling how objects are spawned by Netcode. Netcode by default will allocate new memory when spawning new
12
+
/// objects. With this Networked Pool, we're using custom spawning to reuse objects.
13
+
/// Hooks to NetworkManager's prefab handler to intercept object spawning and do custom actions
Assert.IsNotNull(prefab.GetComponent<NetworkObject>(),$"{nameof(NetworkObjectPool)}: Pooled prefab \"{prefab.name}\" at index {i.ToString()} has no {nameof(NetworkObject)} component.");
70
+
Assert.IsNotNull(
71
+
prefab.GetComponent<NetworkObject>(),
72
+
$"{nameof(NetworkObjectPool)}: Pooled prefab \"{prefab.name}\" at index {i.ToString()} has no {nameof(NetworkObject)} component."
// In this simple example pool we just disable objects while they are in the pool. But we could call a function on the object here for more flexibility.
69
118
go.SetActive(false);
70
-
go.transform.SetParent(transform);
71
119
pooledObjects[prefab].Enqueue(networkObject);
72
120
}
73
121
@@ -95,15 +143,14 @@ private void RegisterPrefabInternal(GameObject prefab, int prewarmCount)
0 commit comments