Describe how you would design a reusable object pool and what trade-offs it has.
What the interviewer wants to hear
- Pre-create objects and reuse them instead of Instantiate and Destroy
- Reset state on get and release, with OnSpawn and OnDespawn hooks
- Decide growth policy: fixed size, grow, or recycle oldest
- Trade memory for fewer allocations and hitches
- Bugs from stale state or references to returned objects; Unity ObjectPool API
Model answer
An object pool keeps a set of inactive objects and hands them out instead of creating new ones, then takes them back instead of destroying them. That avoids allocation and garbage collection spikes, and Instantiate costs. I would build a generic pool, or use Unity's ObjectPool<T>, with create, get, release and destroy callbacks. On get, the object resets its state, like health, velocity and particle systems, and on release it is deactivated. I prewarm the pool during loading to the expected peak, and decide the growth policy: grow with a warning, or recycle the oldest, which suits bullet holes. The trade-offs are memory held all the time, and bugs from objects that keep stale state or from code that still holds a reference after releasing. Debug checks for double release help.
Can you answer it under time pressure?
Take a timed medium round and get scored on every answer.
More medium Game Developer questions
- Your game runs at 40 FPS but must hit 60 FPS. How do you find and fix the problem?
- How would you design a save game system?
- How would you build the AI for an enemy guard that patrols, notices the player, chases and attacks?
- How would you choose between Unity, Unreal and Godot for a new project?
- How do you make game systems easy for designers to tune without changing code?
- How would you build a third-person camera that follows the player smoothly and does not clip through walls?
- Players report that their character sometimes falls through the floor. How do you investigate and fix it?
- How would you design input handling that supports keyboard, gamepad and touch, plus key rebinding?
- How would you procedurally generate dungeon levels that are always playable?