Unity: project structure¶
Folders, assemblies, packages and version control.
Entries are sorted by score from 1 to 10 (criteria): 9–10 start here or strongly recommended, 6–8 recommended, 1–5 further reading or conditional.
Adopted references¶
- 8 Best practices for organizing your Unity project (Unity): follow it for folder layout and naming.
- 8 Introduction to assemblies in Unity and Assembly definitions (Unity Manual).
- 7 Version control (Unity Manual).
Key rules¶
Folders and naming¶
- 7
UNITY-STRUCT-1Agree on one folder structure and naming convention, write it down, and keep your own assets separate from third-party assets. (Unity, Best practices for organizing your Unity project) - 6
UNITY-STRUCT-2Know Unity's reserved folder names (Editor,Resources,StreamingAssets,Plugins, …) and use them only for their purpose. (Unity Manual, Special folder names) - 6
UNITY-STRUCT-3Agree on a team C# style guide, starting from Unity's example and adapting it. Apply it consistently, and enforce formatting with an EditorConfig file. (C# style guide e-book (Unity 6 edition), Unity, Naming and code style tips)
Assemblies and packages¶
- 7
UNITY-STRUCT-4Split code into assemblies with Assembly Definition files once the project grows. This cuts recompilation time. A custom assembly can only use the assemblies it references, and cyclic references aren't allowed, which makes dependency direction explicit. (Unity Manual, Introduction to assemblies, Referencing assemblies) - 7
UNITY-STRUCT-5Mirror the architecture in assemblies, for exampleGame.Core(no engine-specific dependencies where practical),Game.Gameplay,Game.UI,Game.Editorand*.Tests, so that wrong-way references fail to compile. (Unity Manual, Assembly definitions, general: point dependencies inwards) - 4
UNITY-STRUCT-6Move systems that several projects share into custom UPM packages that follow the standard package layout. (Unity Manual, Creating custom packages, Package layout)
Version control¶
- 10
UNITY-STRUCT-7Keep.metafiles visible and committed, and keep asset serialization on Force Text, so that assets diff and merge. Both are the defaults. Don't change them. (Unity Manual, Version control settings, Editor settings: Asset Serialization) - 9
UNITY-STRUCT-8Start from theUnity.gitignoretemplate in github/gitignore, which ignores generated folders such asLibrary/andTemp/. This is how Unity projects applyGAMEDEV-22, together with committing the.metafiles (UNITY-STRUCT-7). (github/gitignore, Unity.gitignore) - 6
UNITY-STRUCT-9Configure UnityYAMLMerge (Smart Merge) as the merge tool for scenes and prefabs. (Unity Manual, Smart Merge)
Iteration speed¶
- 5
UNITY-STRUCT-10Enter Play mode without domain reload for faster iteration. This is the default and Unity's recommendation from Unity 6.6. In 6.0–6.5, choose Reload Scene only. Reset static state yourself, because static fields and static event subscribers keep their values between Play mode sessions. (Unity Manual, Domain reloading, Configurable Enter Play Mode)
How to enforce¶
Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.
- 7 Unity compiler with assembly definitions: code can only use assemblies its assembly definition references, and cyclic references aren't allowed, so wrong-way dependencies fail to compile. Checks
UNITY-STRUCT-4andUNITY-STRUCT-5. - 7 Unity Project Auditor, domain reloading issues: a Roslyn analyzer that finds static fields that keep their value between Play mode runs. Turn on Use Roslyn Analyzers first, and run it from the command line in CI. Partly checks
UNITY-STRUCT-10. - 5 dotnet format: checks code against
.editorconfig, and with--verify-no-changesit fails CI when formatting differs. Without generated project files it can only check whitespace (dotnet format whitespace --folder). ChecksUNITY-STRUCT-3.