mono-pool-spawn-unity
Unity Mono Runtime Spawning: Use IObjectPoolManager + Prefabs
Section titled “Unity Mono Runtime Spawning: Use IObjectPoolManager + Prefabs”Scope: Unity Mono (MonoBehaviour/GameObject) only. Writing an
ISystem/IComponentData/DOTS module? Stop: DOTS spawning isEntityManager/ECB (t1k-unity-dots-core-ecs,t1k-unity-dots-core-entity-command-buffer).
In MonoBehaviour / GameObject code, never use new GameObject(...) or Object.Instantiate(...) to spawn runtime objects. Create a prefab, register it as an Addressable, and spawn/recycle through TheOne.Pooling.IObjectPoolManager.
| Want to spawn… | Use |
|---|---|
A view bound to a MonoBehaviour | IObjectPoolManager.Spawn<T>(key, ..., parent, spawnInWorldSpace: false) |
A pure Mono entity (TheOne’s IEntityManager) | IEntityManager.Spawn<T>() |
| A short-lived one-shot burst | A resident ParticleSystem + Emit(EmitParams, n) — see VFX carve-outs |
| A VFX needing its own GameObject | IObjectPoolManager.Spawn(key, position) |
| A DOTS entity | Out of scope: EntityManager.CreateEntity / ECB |
Why: new GameObject + AddComponent hits the managed boundary every spawn, producing GC pressure; pool spawn reuses a pre-loaded instance.
VFX carve-outs, pool-spawn ONLY when the effect needs its own GameObject: sub-emitters/per-instance material override · an attached script or moving-transform parenting · looping/long-lived effects · per-instance module/simulation-space/sort-order settings. Otherwise use Emit(EmitParams, n) on a resident ParticleSystem.
Full detail
Section titled “Full detail”Seven-step recipe, the four does-not-apply cases (DOTS/ECS, hybrid baking authoring, editor-only tooling, one-off bootstrap objects), and the replaceability test: docs/mono-pool-spawn-unity.md.
Related
Section titled “Related”code-conventions-unity.md · t1k-unity-base-game-patterns · t1k-unity-base-addressables · game-feedback-mandate-unity.md