Async Hierarchy Activation Without Frame Spikes
While working on REM, I ran into an annoying performance problem. Many of the dream spaces are built out of hundreds of objects organized into large hierarchies. The scenes themselves loaded quickly but whenever the player walks into a ‘zone’ I activate the hierarchy and the game stutters, breaking immersion.
Some profiling revealed that the biggest framerate hits were from larger, more interactive, zones.
The Problem: SetActive Isn’t Cheap at Scale
When you call
SetActive(true) on a parent object, Unity recursively enables every child beneath it.For small hierarchies, this is basically free. For REM’s environments—dense dream spaces full of props, lights, colliders, VFX, and scripts—it becomes a real CPU spike.
The Idea: Don’t Activate Everything at Once
The fix was simple in concept: stop doing all the work in one frame.
Instead of enabling an entire hierarchy immediately, I spread activation across multiple frames.
So rather than:
- Enable root
- Unity recursively enables everything instantly
- Frame spike
I moved toward:
- Enable root
- Queue children
- Activate gradually over time
The System: Async Hierarchy Activation
The system itself ended up being pretty lightweight:
- Root object stays active
- Children start disabled
- A queue tracks what needs activation
- A small batch is processed each frame
- Repeat until the hierarchy is fully active
This approach scales automatically. Small zones feel instant and large zones smooth out over a short window. Worst-case hierarchies no longer produce a single-frame hitch.
The flexibility that this affords me fits the way I build scenes: quick and iterative.