# 6. Procedural Generation Pitfalls Part of [[Procedural Generation]]. Prev: [[5. Worked Example Seeded Dungeon]]. ## Global `Random` polluted mid-generate Another system calling `Random.Range` during `Build` changes the layout. Use `InitState` once at the start *or* a private `System.Random`. Do not mix. ## "It worked at seed 1" Test a dozen seeds. Log failures. A generator that only works on the seed you demoed is a scripted level in denial. ## Overlap and floating corridors Always test AABBs. A corridor that does not meet both sockets is a fall-through. ## Scaling prefabs to fit Breaks metrics, lightmaps, and sockets. Swap a different template, do not `localScale = (1.2, 1, 0.7)`. ## Key behind the lock Constraint, not a playtest surprise. Fail the seed. ## Runtime generate on Quest boot Bake, stream, or keep the graph tiny ([[6. Quest Performance Budgets]]). ## Deleting the wrong objects The factory owns one parent. It must not `Destroy` the rest of the scene. In the Editor, prefer Undo-registered creates. ## Replacing design If every run is a parking garage, the recipe is under-constrained. Add beats and a weenie, or go back to a hand gray-box ([[4. Beat-Chart to Gray-Box]]). ## Terrain noise by habit Heightmaps live in [[Terrain]]. This series places rooms. ## Sources - `Random.InitState` (6000.5): https://docs.unity3d.com/6000.5/Documentation/ScriptReference/Random.InitState.html