Odin Inspector Standards
Use Odin Inspector to enhance the Unity Editor experience, ensure data integrity, and provide a clear UI for designers.
🛑 Validation Attributes (MANDATORY)
Validation attributes prevent runtime errors by catching missing dependencies or invalid data in the Editor.
| Attribute | Use Case | Example |
|---|---|---|
[Required] | Mandatory reference (Prefab, Component, ScriptableObject) | [Required] public GameObject Prefab; |
[AssetsOnly] | Field must be an Asset (Prefab/SO), NOT a scene object | [AssetsOnly] public AttackDefinition Data; |
[SceneObjectsOnly] | Field must be in the Scene (Manager, UI Element) | [SceneObjectsOnly] public Transform SpawnPoint; |
[ValidateInput] | Custom logical validation | [ValidateInput("ValidateRange", "Range must be positive")] |
[InfoBox] | Provide context or warnings to designers | [InfoBox("This attack scales with Level")] |
🎨 Layout & Organization
Keep the Inspector clean and scannable by grouping related fields.
| Grouping | Description |
|---|---|
[BoxGroup] | Wrap fields in a titled box |
[HorizontalGroup] | Place fields side-by-side |
[TabGroup] | Organize data into tabs (Impact, Visual, Audio) |
[FoldoutGroup] | Hide advanced settings by default |
[Title] | Add a clear header above a section |
📁 Asset Management
Enhance asset picking and visualization.
| Attribute | Description |
|---|---|
[AssetList] | Show a list of all matching assets in the project |
[ValueDropdown] | Provide a dropdown of valid string keys or assets |
[InlineEditor] | Preview and edit the referenced asset (SO) within the current inspector |
[FilePath] | Pick a file relative to the project |
[FolderPath] | Pick a directory |
🚀 Best Practices
- •Safety First: Use
[AssetsOnly]whenever a field is intended for a Prefab. This prevents the "Prefab referencing Scene Object" bug which causes missing references when the scene changes. - •Designer Experience: Use
[BoxGroup]and[HorizontalGroup]to minimize scrolling. - •Meaningful Error Messages: When using
[ValidateInput], provide clear instructions on how to fix the error. - •Auto-Discovery: Use
[ValueDropdown]with a helper method to list available entries (e.g., Audio Keys, Scene Names).
Verification
Before finalizing an Inspector-heavy class:
- • Are all critical references marked
[Required]? - • Are project assets constrained with
[AssetsOnly]? - • Is the layout organized into meaningful groups?
- • Do
[ValueDropdown]methods return valid options?