Skip to content

prefab-only-construction-unity

Prefab-Only Construction (Unity): No Code-Built GameObjects / UI / Scene-Wiring

Section titled “Prefab-Only Construction (Unity): No Code-Built GameObjects / UI / Scene-Wiring”

Scope: Unity Mono (MonoBehaviour / GameObject / uGUI) runtime & gameplay code. Does NOT govern DOTS/ECS entities, editor-only tooling, or tests (see Carve-outs).

In Unity runtime/gameplay code you MUST NOT construct GameObjects, UI, visual hierarchies, or wire scene references in code. Everything visual/structural is authored as a prefab and spawned as a prefab at runtime; references are assigned in the Inspector.

The ONE permitted construction form: spawn a prefab.

// Author CardView.prefab in the editor, then:
var view = Instantiate(this.cardPrefab, this.boardRoot); // or pool.Spawn(...)
view.Configure(this.config, size); // set DATA on existing refs

Instantiate(prefab, parent) is allowed and encouraged. Prefer a pool (IObjectPoolManager.Spawn<T>(...), see mono-pool-spawn-unity.md) for anything spawned/recycled repeatedly. Configure via a Configure(...)/Bind(...) method that sets data on already-serialized child refs; it must NOT create children.

The full banned-pattern list, the t1k unity authoring table, and the carve-outs live in the body of whichever agent constructs Unity UI/GameObjects at runtime (t1k-unity-base-ui-developer.md, t1k-unity-base-developer.md).

Why, how to apply, and the review test: docs/prefab-only-construction-unity.md.

mono-pool-spawn-unity.md · code-conventions-unity.md · library-quality-mandate-unity.md (naming charter) · t1k-unity-ui-create-prefab (t1k unity eval / YAML authoring recipe)