# 2. Room Templates as ScriptableObjects Part of [[Procedural Generation]]. Prev: [[1. Data-Driven Rooms not Heightmaps]]. Next: [[3. Seeded Graphs and Corridors]]. A **RoomTemplate** is Type Object data ([[ScriptableObject Architecture]]): it names a prefab, a size, connection **sockets**, and tags the recipe can ask for (`Entrance`, `Combat`, `Treasure`, `Weenie`, `Lock`, `Key`). ```csharp using System; using UnityEngine; public enum RoomTag { Entrance, Combat, Treasure, Weenie, Lock, Key, Exit } [Serializable] public struct RoomSocket { public Vector3 localPosition; public Vector3 localForward; // corridor leaves this way public bool required; } /// <summary>Data only. NOT compiled in Unity.</summary> [CreateAssetMenu(menuName = "Tutorials/Room Template")] public sealed class RoomTemplate : ScriptableObject { public GameObject prefab; public Vector3 size = new Vector3(8f, 3f, 8f); public RoomTag[] tags = { RoomTag.Combat }; public RoomSocket[] sockets; } ``` The **prefab** is a gray-box room built to [[2. Movement Metrics Asset]] (door widths, ceiling, a `MetricsGym`-friendly floor). Sockets are empty child markers you can also read from the prefab at bake time if you would rather author them in the scene than in the asset - pick one source of truth. A **DungeonRecipe** holds the seed, target room count, and the allowed templates: ```csharp [CreateAssetMenu(menuName = "Tutorials/Dungeon Recipe")] public sealed class DungeonRecipe : ScriptableObject { public int seed = 1; public int roomCount = 6; public RoomTemplate[] templates; public RoomTemplate entrance; public RoomTemplate exit; } ``` Do not put generation code on the template asset. The factory is a separate `DungeonGenerator`. ## Exercise Build three prefabs: entrance (one socket), hallway-capable combat room (two+ sockets), dead-end treasure (one socket). One ScriptableObject each. If the door is 1 m and your character is 0.8 m wide, you already failed metrics - fix the prefab, not the generator. ## Sources - [[ScriptableObject Architecture]] - [[2. Movement Metrics Asset]]