Skip to content

t1k:unity:dots-core:procgen

FieldValue
Moduledots-core
Version3.56.1
Effortlow
Tools—
/t1k:unity:dots-core:procgen

DOTS Procedural Generation — Floor & Room System

Section titled “DOTS Procedural Generation — Floor & Room System”

Package: com.the1studio.dots-core — namespace DOTSCore.ProceduralGen Related skills: t1k-unity-dots-core-ecs (API) · t1k-unity-dots-nav-agents-navigation (room pathfinding)

  • Building dungeon floors, room chains, procedural map layout
  • Implementing seeded deterministic random for runs
  • Designing room type taxonomy (Combat/Shop/Treasure/Event/Boss)
  • Using FloorConfig.GenerateRequested flag to trigger generation
ComponentTypePurpose
FloorConfigIComponentData (singleton)RoomCount, Seed, FloorNumber, GenerateRequested flag
RunSeedREMOVED 2026-08-21 (ff45564a, “complete RunSeed deprecation”)Was IComponentData (singleton), [Obsolete] — uint Value (not Seed) — the deprecation’s one-release grace window closed; the type and its propagation system (SeededRandomSystem, below) no longer exist in source. Use DOTSCore.GameFlow.RunScopeSingleton.RunSeed directly — this was already the recommended migration target while RunSeed existed
RoomTemplateIComponentDataint2 Size, RoomType Type, FixedString64Bytes TemplateId
RoomConnectionIBufferElementData (cap 4)Entity ConnectedRoom, int2 DoorPosition
public enum RoomType { Combat, Shop, Treasure, Event, Boss }
SystemGroupRole
SeededRandomSystemREMOVED 2026-08-21 (ff45564a)Was [UpdateInGroup(typeof(CoreSystemGroup), OrderFirst = true)], copying RunScopeSingleton.RunSeed into the legacy RunSeed singleton for consumers not yet migrated. Deleted alongside RunSeed — there is nothing to propagate to anymore. Read RunScopeSingleton.RunSeed directly; Random.CreateFromIndex still lives in ProceduralMapSystem below, unaffected by this removal
ProceduralMapSystemCoreSystemGroupDetects FloorConfig.GenerateRequested; creates room entity chain with RoomTemplate + RoomConnection buffers
// Bake FloorConfig singleton in authoring:
var e = baker.GetEntity(TransformUsageFlags.None);
baker.AddComponent(e, new FloorConfig
{
RoomCount = 8,
Seed = 12345,
FloorNumber = 1,
GenerateRequested = true // ProceduralMapSystem detects this flag
});
// ProceduralMapSystem derives deterministic random per floor from FloorConfig.Seed directly.
// (SeededRandomSystem, which used to keep a legacy RunSeed singleton in sync, was removed
// 2026-08-21 alongside RunSeed itself — nothing propagates into FloorConfig.Seed; it's set at
// bake time or by the re-trigger snippet below.)
var rng = Random.CreateFromIndex(config.Seed + (uint)config.FloorNumber);
// Actual assignment in ProceduralMapSystem — note Boss is tested FIRST,
// so a 1-room floor is a Boss room, not a Combat room:
RoomType roomType;
if (i == roomCount - 1) roomType = RoomType.Boss;
else if (i == 0) roomType = RoomType.Combat;
else
{
int roll = rng.NextInt(0, 100); // integer roll, single draw
roomType = roll < 50 ? RoomType.Combat
: roll < 70 ? RoomType.Treasure
: roll < 85 ? RoomType.Shop
: RoomType.Event; // 50 / 20 / 15 / 15
}

Two passes, not one. A single loop that creates room i and immediately appends a connection to rooms[i+1] forward-references an entity that does not exist yet — rooms[i+1] is still the array’s default Entity (all-zero) at that point, so the connection silently points at nothing. Create every room first, THEN wire connections in a second pass once the whole rooms array is populated.

using var rooms = new NativeArray<Entity>(config.RoomCount, Allocator.Temp);
// Pass 1 — create every room entity + RoomTemplate. No connections yet: rooms[i+1]
// does not exist until this loop finishes.
for (int i = 0; i < config.RoomCount; i++)
{
rooms[i] = ecb.CreateEntity();
ecb.AddComponent(rooms[i], new RoomTemplate { Type = types[i], ... });
}
// Pass 2 — wire bidirectional connections now that every rooms[i] is a real entity.
for (int i = 0; i < config.RoomCount; i++)
{
var buffer = ecb.AddBuffer<RoomConnection>(rooms[i]);
if (i > 0) buffer.Add(new RoomConnection { ConnectedRoom = rooms[i-1], DoorPosition = new int2(5, 0) });
if (i < config.RoomCount - 1) buffer.Add(new RoomConnection { ConnectedRoom = rooms[i+1], DoorPosition = new int2(5, 10) });
}
// rooms NativeArray disposed after loop — entities live in ECB until playback
// On floor transition: set flag, bump FloorNumber
SystemAPI.GetSingletonRW<FloorConfig>().ValueRW.FloorNumber++;
SystemAPI.GetSingletonRW<FloorConfig>().ValueRW.GenerateRequested = true;
DirectionPackageDetail
Depends onDOTSCore baseECB, Random, FixedString64Bytes
Soft dependencyDOTSCore.NavigationRoom graph → pathfinding between rooms (future hook)
Used byChaosForgeDemo8-room dungeon per run with typed rooms
  • ChaosForgeDemo — generates 8-room dungeon; ForgeHome, Combat, Shop, Boss room types
  • BattleDemo — uses RoomTemplate as encounter zones with custom metadata attached
  • Linear chain only — current impl creates a straight dungeon (no branching). Code comment flags “optional branches” as future work. For branching graphs, the consumer must extend ProceduralMapSystem or post-process connections.
  • Boss hardcoded to last room — RoomType.Boss is assigned unconditionally at index == RoomCount - 1. To override boss placement, modify FloorConfig struct or post-process connections after generation.
  • NativeArray must be disposed after ECB loop — room entities exist in the ECB; the NativeArray<Entity> holding their IDs is temp-allocated and MUST be disposed before OnUpdate returns.
  • ProceduralMapSystem has no OnCreate and no RequireForUpdate — and does not need one. It is guarded by [RequireMatchingQueriesForUpdate] plus a SystemAPI.Query<RefRW<FloorConfig>>() foreach, which simply iterates zero times before the singleton bakes. There is no frame-1 crash. (An earlier version of this skill asserted the opposite; corrected 2026-08-12 against source.)
  • FloorConfig is read as a QUERY, not a singleton. The system iterates every FloorConfig entity, so two of them means two floors generated in the same frame. The GetSingletonRW<FloorConfig>() call in the re-trigger snippet above is fine for the normal one-config case, but the system itself imposes no singleton constraint — do not assume one.
  • Seed + FloorNumber uniqueness — if two floors have the same Seed + FloorNumber value, they generate identically. Use the per-run base seed from DOTSCore.GameFlow.RunScopeSingleton.RunSeed + floor offset for variety — the standalone RunSeed component and its SeededRandomSystem propagator are gone as of 2026-08-21 (ff45564a), so RunScopeSingleton.RunSeed is now the ONLY source, not merely the recommended one.