Programming & Technical Apr 17, 2026

How to Profile CPU Spikes From Spawn Waves in Unity 6 and Godot 4 Without Guesswork

Learn how to profile CPU spikes from spawn waves in Unity 6 and Godot 4 using repeatable capture loops, marker discipline, and regression checks that hold up in production.

By GamineAI Team

How to Profile CPU Spikes From Spawn Waves in Unity 6 and Godot 4 Without Guesswork

Spawn waves are where many indie action games quietly fall apart. The game feels fine with 5 enemies, maybe even 20, then one wave starts and frame time jumps hard. The common trap is "fixing what looks expensive" instead of proving what is expensive.

This guide gives you a repeatable profiling workflow for Unity 6 and Godot 4 so you can isolate spawn-wave CPU spikes, apply the right fix, and verify that the gain survives build conditions.

If you are already working through related systems, keep these nearby:

Taxi Time illustration used as blog thumbnail for spawn-wave CPU profiling

Why spawn-wave spikes are hard to debug

Wave spikes are usually a stacked event, not one bad line:

  • object creation bursts
  • AI initialization in the same frame
  • pathing updates syncing at spawn time
  • animation graph warm-up
  • first-time VFX/audio allocations

If you only inspect average frame time, you miss the spike shape and blame the wrong system.

Step 1 - Build one deterministic test route

Before opening any profiler, create a stable test:

  1. same map section
  2. same spawn timing
  3. same wave size
  4. same player behavior (or scripted replay)

Your goal is to compare captures against a fixed baseline. Without deterministic input, every profile is a different experiment.

Pro tip: Keep one "wave stress scene" checked into source control. Treat it as a performance unit test.

Step 2 - Capture in the right environment

Editor captures are useful, but not final truth.

Run at least:

  • one editor profile for fast iteration
  • one development build profile for realism

Spawn waves often look fine in editor and regress in build due to different threading behavior, stripping, or content loading paths.

Step 3 - Tag the wave boundary in code

Do not scroll timelines guessing where wave start happened. Add explicit markers/log boundaries.

For Unity, use profiler markers around:

  • wave scheduler tick
  • spawn loop
  • post-spawn initialization

For Godot, add consistent log timestamps or custom monitor counters around the same boundaries.

This turns "somewhere around here" into exact timing windows.

Step 4 - Split spike analysis into three buckets

When a spike appears, classify it first:

1) Spawn burst cost

Instantiation, scene-tree attach, component setup.

2) First-frame simulation cost

AI state boot, path requests, physics registration.

3) Side-effect cost

VFX, audio, UI updates, telemetry events.

Most teams waste hours because they try to optimize rendering when the spike is actually first-frame AI boot plus pathfinding fan-out.

Unity 6 quick triage pattern

In Unity 6 Profiler:

  1. locate the frame spike around wave marker
  2. inspect main thread and worker threads separately
  3. expand scripts and job timelines for spawn frame
  4. note top 3 contributors by milliseconds

Common Unity wave offenders:

  • pooled objects still doing heavy OnEnable work
  • multiple systems subscribing/unsubscribing per spawn
  • nav/path calls firing for all enemies in one frame
  • animation controller parameter setup spikes

Fix strategy that usually works:

  • stagger heavy init across several frames
  • prewarm path/animation assets before wave
  • batch lightweight setup, defer expensive setup

Godot 4 quick triage pattern

In Godot 4:

  1. use the Profiler and Monitor views during deterministic wave run
  2. compare frame-time spikes against node creation and physics activity
  3. inspect script hotspots in spawn and _ready paths
  4. test spawn batch size reductions to see spike shape change

Common Godot offenders:

  • large PackedScene.instantiate() bursts in one tick
  • expensive _ready() logic on every enemy
  • signal wiring done repeatedly with extra allocations
  • navigation or collision updates synchronized on spawn

Fix strategy that usually works:

  • staged spawn queue instead of one-frame flood
  • move heavy setup out of _ready() where possible
  • cache shared references/resources before wave
  • spread path requests over a short window

Step 5 - Verify the fix with A/B capture

Never trust one "good-looking" run.

Do:

  • baseline capture (before fix)
  • variant capture (after fix)
  • same deterministic route
  • compare p95/p99 frame time around wave windows

If spike moved from frame 220 to frame 228, but stayed equally large, you did not solve it. You delayed it.

Fast checklist before merging performance fixes

Use this pass before shipping:

  1. spike reduced in both editor and development build
  2. no new hitch introduced in later wave
  3. memory allocation pattern not worsened
  4. fix documented with capture screenshot or timing notes
  5. one rollback note if fix touches spawn architecture

Common mistakes to avoid

  • optimizing average FPS instead of spike frames
  • profiling with inconsistent test routes
  • mixing multiple fixes before measuring each one
  • trusting editor-only captures as final evidence
  • ignoring p95/p99 in favor of one clean frame

FAQ

Should I solve spawn spikes with pooling only

Pooling helps, but it is not enough if pooled objects still perform expensive initialization when activated. Measure activation cost, not just instantiation cost.

How many frames should I spread spawn initialization over

Start small: 3 to 8 frames for heavy waves. Then profile. The right number depends on game feel and enemy behavior requirements.

What is a good target metric for wave smoothness

For action games, focus on p95 and p99 frame-time stability during waves, not only average FPS. Stable worst-case frames matter more than pretty averages.

Should I profile AI and pathing separately from spawning

Yes. Separate them in markers and test toggles. If you cannot isolate systems, you cannot prioritize fixes correctly.

How often should we re-run wave profiling

At least once per milestone and after major AI/content pipeline changes. Spawn regressions often reappear through unrelated feature work.

Conclusion

CPU spike debugging gets dramatically easier when you stop treating it like a mystery and treat it like a controlled experiment. A deterministic route, clear wave markers, and A/B capture discipline will save you from placebo optimizations and late-night guesswork.

If this helped, bookmark it for your next combat pass and share it with the teammate who owns spawn systems or performance triage.