Skip to content
Skills Library
Programming · Building & coding

unity-editor-tools

/unity-editor-tools

Unity 6 editor scripting and custom tools guide. Use when creating custom inspectors, EditorWindows, PropertyDrawers, Gizmos, Handles, menu items, or editor extensions. Covers SerializedObject/SerializedProperty pattern, AssetDatabase, and editor-only code with #if UNITY_EDITOR. Based on Unity 6.3 LTS documentation.

Licence
MIT
Last repository change
07.07.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
4
Scripts
0
HTML comments
0
URLs in SKILL.md
11
Deprecation

No signals detected. Repository changed on 07.07.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Unity 6 editor scripting and custom tools guide. Use when creating custom inspectors, EditorWindows, PropertyDrawers, Gizmos, Handles, menu items, or editor extensions. Covers SerializedObject/SerializedProperty pattern, AssetDatabase, and editor-only code with #if UNITY_EDITOR. Based on Unity 6.3 LTS documentation.

Original author description

Unity 6 editor scripting and custom tools guide. Use when creating custom inspectors, EditorWindows, PropertyDrawers, Gizmos, Handles, menu items, or editor extensions. Covers SerializedObject/SerializedProperty pattern, AssetDatabase, and editor-only code with #if UNITY_EDITOR. Based on Unity 6.3 LTS documentation.

How it works

  1. Editor Scripting Overview
  2. Custom Inspector (Editor)
  3. PropertyDrawer and PropertyAttribute
  4. EditorWindow
  5. MenuItem
  6. Gizmos and Handles
  7. SerializedObject Pattern
  8. AssetDatabase
  9. Common Patterns
  10. Anti-Patterns
Original SKILL.md headings · 410 lines, 1,354 words
SKILL.md preview
---
name: unity-editor-tools
description: >
  Unity 6 editor scripting and custom tools guide. Use when creating custom inspectors, EditorWindows, PropertyDrawers, Gizmos, Handles, menu items, or editor extensions. Covers SerializedObject/SerializedProperty pattern, AssetDatabase, and editor-only code with #if UNITY_EDITOR. Based on Unity 6.3 LTS documentation.
---

# Unity Editor Tools

## Editor Scripting Overview

Editor scripts extend the Unity Editor with custom inspectors, windows, tools, and workflows. All editor code must either live in an `Editor/` folder or be wrapped in `#if UNITY_EDITOR` / `#endif` -- this ensures editor code is stripped from runtime builds.

Unity 6.3 supports two GUI frameworks for editor extensions:

| Framework | Status | Entry Point |
|-----------|--------|-------------|
| **UI Toolkit** | Recommended | `CreateInspectorGUI()` / `CreateGUI()` returning `VisualElement` |
| **IMGUI** | Legacy, fully functional | `OnInspectorGUI()` / `OnGUI()` |

Key base classes: `Editor`, `EditorWindow`, `PropertyDrawer`, `DecoratorDrawer`, `ScriptableWizard`.

---

## Custom Inspector (Editor)

Derive from `Editor`, apply `[CustomEditor(typeof(TargetType))]`. See `references/custom-inspectors.md` for full guide.

### UI Toolkit (Recommended)

```csharp
[CustomEditor(typeof(MyPlayer))]
public class MyPlayerEditor : Editor
{
    public override VisualElement CreateInspectorGUI()
    {
        VisualElement root = new VisualElement();
        var visualTree = Resources.Load("MyPlayerEditor") as VisualTreeAsset;
        visualTree.CloneTree(root);
        return root;
    }
}
```

When `CreateInspectorGUI()` is overridden, `OnInspectorGUI()` is ignored.

### IMGUI with SerializedObject Pattern

```csharp
[CustomEditor(typeof(LookAtPoint))]
[CanEditMultipleObjects]
public class LookAtPointEditor : Editor
{
    SerializedProperty lookAtPoint;

    void OnEnable() { lookAtPoint = serializedObject.FindProperty("lookAtPoint"); }

    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        EditorGUILayout.PropertyField(lookAtPoint);
        serializedObject.ApplyModifiedProperties();
    }
}
```

### Key Members

| Member | Description |
|--------|-------------|
| `target` / `targets` | Inspected object(s) |
| `serializedObject` | SerializedObject for the target(s) |
| `DrawDefaultInspector()` | Renders built-in default inspector |
| `OnSceneGUI()` | Draw interactive Handles in Scene View |

### Scene View Integration

```csharp
public void OnSceneGUI()
{
    var t = (LookAtPoint)target;
    EditorGUI.BeginChangeCheck();
    Vector3 pos = Handles.PositionHandle(t.lookAtPoint, Quaternion.identity);
    if (EditorGUI.EndChangeCheck())
    {
        Undo.RecordObject(target, "Move look-at point");
        t.lookAtPoint = pos;
    }
}
```

---

## PropertyDrawer and PropertyAttribute

Customize how serialized fields appear in the Inspector. See `references/property-drawers.md` for full guide.

**1. Define attribute (runtime code, outside Editor folder):**

```csharp
public class MyRangeAttribute : PropertyAttribute
{
    public readonly float min, max;
    public MyRangeAttribute(float min, float max) { this.min = min; this.max = max; }
}
```

**2. Implement drawer (Editor folder):**

```csharp
[CustomPropertyDrawer(typeof(MyRangeAttribute))]
public class MyRangeDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        MyRangeAttribute range = (MyRangeAttribute)attribute;
        if (property.propertyType == SerializedPropertyType.Float)
            EditorGUI.Slider(position, property, range.min, range.max, label);
        else if (property.propertyType == SerializedPropertyType.Integer)
            EditorGUI.IntSlider(position, property, (int)range.min, (int)range.max, label);
    }
}
```

**Critical rules:** Must be in `Editor/` folder. Use `EditorGUI` (not `EditorGUILayout`). Use `EditorGUI.BeginProperty()`/`EndProperty()` for prefab overrides. Cannot mix UI Toolkit and IMGUI in one drawer.

---

## EditorWindow

Custom dockable editor windows. See `references/editor-windows.md` for full guide.

**Lifecycle:** OnEnable -> CreateGUI -> Update -> OnGUI -> OnDisable

```csharp
public class MyToolWindow : EditorWindow
{
    [MenuItem("Tools/My Tool Window")]
    public static void ShowWindow()
    {
        var window = GetWindow<MyToolWindow>();
        window.titleContent = new GUIContent("My Tool");
        window.minSize = new Vector2(300, 200);
    }

    public void CreateGUI()
    {
        rootVisualElement.Add(new Label("Hello from UI Toolkit!"));
        rootVisualElement.Add(new Button(() => Debug.Log("Clicked!")) { text = "Click Me" });
    }
}
```

| Static Method | Description |
|---------------|-------------|
| `GetWindow<T>()` | Get existing or create new |
| `CreateWindow<T>()` | Always create new instance |
| `HasOpenInstances<T>()` | Check if open |

| Display Mode | Behavior |
|-------------|----------|
| `Show()` | Standard dockable |
| `ShowUtility()` | Floating, not dockable |
| `ShowModal()` | Modal dialog |
| `ShowAsDropDown()` | Dropdown popup |

---

## MenuItem

The `[MenuItem]` attribute converts static methods into menu commands.

```csharp
[MenuItem("Menu/Path/Item Name", isValidateFunction, priority)]
```

| Prefix | Placement |
|--------|-----------|
| `"Tools/..."` | Custom tools menu |
| `"Assets/..."` | Assets menu + Project context menu |
| `"GameObject/..."` | GameObject menu + Hierarchy context menu |
| `"CONTEXT/ComponentType/..."` | Component context menu |

**Shortcut modifiers:** `%` = Cmd/Ctrl, `#` = Shift, `&` = Alt, `^` = Ctrl (all), `_` = no modifier.

```csharp
// Validation function controls when menu item is enabled
[MenuItem("Tools/Reset Position", true)]
static bool ValidateResetPosition() => Selection.activeTransform != null;

[MenuItem("Tools/Reset Position", false)]
static void ResetPosition()
{
    Undo.RecordObject(Selection.activeTransform, "Reset Position");
    Selection.activeTransform.position = Vector3.zero;
}
```

**GameObject creation** (use priority 10):

```csharp
[MenuItem("GameObject/Custom/My Object", false, 10)]
static void CreateMyObject(MenuCommand menuCommand)
{
    var go = new GameObject("My Object");
    GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
    Undo.RegisterCreatedObjectUndo(go, "Create My Object");
    Selection.activeObject = go;
}
```

---

## Gizmos and Handles

### Gizmos -- Visual Debugging in Scene/Game View

All drawing inside `OnDrawGizmos()` (always) or `OnDrawGizmosSelected()` (when selected):

```csharp
void OnDrawGizmos()
{
    Gizmos.color = Color.yellow;
    Gizmos.DrawWireSphere(transform.position, radius);
}

void OnDrawGizmosSelected()
{
    Gizmos.color = Color.red;
    Gizmos.DrawSphere(transform.position, radius);
}
```

**Methods:** `DrawLine`, `DrawRay`, `DrawSphere`, `DrawWireSphere`, `DrawCube`, `DrawWireCube`, `DrawMesh`, `DrawWireMesh`, `DrawFrustum`, `DrawIcon`. **Properties:** `color`, `matrix`.

### Handles -- Interactive 3D Controls (Editor Only)

Used inside `OnSceneGUI()` on custom Editors:

```csharp
[CustomEditor(typeof(CircleLayout))]
public class CircleLayoutEditor : Editor
{
    public void OnSceneGUI()
    {
        var t = (CircleLayout)target;
        Handles.color = new Color(1f, 0.8f, 0.4f, 1f);
        Handles.DrawWireDisc(t.transform.position, t.transform.up, t.radius);
        Handles.Label(t.transform.position, $"Radius: {t.radius:F1}");

        EditorGUI.BeginChangeCheck();
        float newRadius = Handles.RadiusHandle(Quaternion.identity, t.transform.position, t.radius);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(t, "Change Radius");
            t.radius = newRadius;
        }
    }
}
```

**Methods:** `PositionHandle`, `RotationHandle`, `ScaleHandle`, `FreeMoveHandle`, `RadiusHandle`, `DrawLine`, `DrawWireDisc`, `Label`, `BeginGUI`/`EndGUI`. **Properties:** `color`, `matrix`.

---

## SerializedObject Pattern

The standard way to edit properties in editor scripts. Provides automatic Undo, multi-object editing, and prefab override tracking.

**Three-step pattern:**

```csharp
serializedObject.Update();                                          // 1. Sync from target
EditorGUILayout.PropertyField(serializedObject.FindProperty("myField")); // 2. Draw/modify
serializedObject.ApplyModifiedProperties();                         // 3. Apply with undo
```

| Member | Description |
|--------|-------------|
| `Update()` | Refresh from target |
| `ApplyModifiedProperties()` | Commit changes with undo |
| `FindProperty(string)` | Get SerializedProperty by name |
| `GetIterator()` | Iterate all properties |
| `targetObject` / `targetObjects` | Inspected object(s) |
| `hasModifiedProperties` | True when unapplied changes exist |

For multi-object editing: add `[CanEditMultipleObjects]` and always use `SerializedProperty` instead of `target`.

---

## AssetDatabase

Programmatic asset access in editor scripts.

```csharp
// Create
var data = ScriptableObject.CreateInstance<MyData>();
AssetDatabase.CreateAsset(data, "Assets/Data/MyData.asset");
AssetDatabase.SaveAssets();

// Load
var loaded = AssetDatabase.LoadAssetAtPath<MyData>("Assets/Data/MyData.asset");

// Find by type
string[] guids = AssetDatabase.FindAssets("t:MyData");
foreach (string guid in guids)
{
    string path = AssetDatabase.GUIDToAssetPath(guid);
    var asset = AssetDatabase.LoadAssetAtPath<MyData>(path);
}

// Other operations
AssetDatabase.GetAssetPath(myObject);
AssetDatabase.DeleteAsset("Assets/Data/OldData.asset");
AssetDatabase.Refresh();
```

**Key methods:** `CreateAsset`, `LoadAssetAtPath<T>`, `FindAssets`, `GetAssetPath`, `AssetPathToGUID`/`GUIDToAssetPath`, `SaveAssets`, `Refresh`, `DeleteAsset`, `CopyAsset`, `MoveAsset`, `RenameAsset`, `ImportAsset`.

---

## Common Patterns

```csharp
// Editor-only guard
#if UNITY_EDITOR
using UnityEditor;
// editor code
#endif

// Change detection
EditorGUI.BeginChangeCheck();
// ... controls ...
if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Change"); }

// ScriptableObject creation menu
[CreateAssetMenu(fileName = "NewConfig", menuName = "Game/Config Data", order = 1)]
public class ConfigData : ScriptableObject { public float moveSpeed = 5f; }

// Default inspector + extras
[CustomEditor(typeof(MyComponent))]
public class MyComponentEditor : Editor
{
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        if (GUILayout.Button("Do Something")) { ((MyComponent)target).DoSomething(); }
    }
}
```

---

## Anti-Patterns

| Anti-Pattern | Problem | Fix |
|-------------|---------|-----|
| Editing `target` without Undo | No undo, no dirty flag | Use SerializedObject or `Undo.RecordObject()` |
| `target` with `[CanEditMultipleObjects]` | Only modifies first object | Use `SerializedProperty` |
| Editor code outside `Editor/` without `#if UNITY_EDITOR` | Build failures | Use `Editor/` folder or preprocessor guard |
| `EditorGUILayout` in PropertyDrawer | Not supported | Use `EditorGUI` with Rect |
| Missing `serializedObject.Update()` | Stale data | Always call before reading |
| Missing `ApplyModifiedProperties()` | Changes lost | Always call after modifications |
| Mixing UI Toolkit + IMGUI in one PropertyDrawer | Not supported | Choose one framework |
| Missing `Undo.RegisterCreatedObjectUndo()` | Cannot undo creation | Always register new objects |
| Missing `GameObjectUtility.SetParentAndAlign()` | Wrong hierarchy parenting | Use in GameObject menu items |
| Heavy work in `OnInspectorGUI()`/`OnGUI()` | Lag (called many times/frame) | Cache in `OnEnable()` |

---

## Key API Quick Reference

```
Editor:        [CustomEditor(typeof(T))], [CanEditMultipleObjects]
               CreateInspectorGUI(), OnInspectorGUI(), OnSceneGUI()
               DrawDefaultInspector(), target, targets, serializedObject

EditorWindow:  GetWindow<T>(), CreateWindow<T>(), CreateGUI(), OnGUI()
               rootVisualElement, titleContent, Show/ShowUtility/ShowModal

PropertyDrawer: [CustomPropertyDrawer(typeof(T))]
               CreatePropertyGUI(), OnGUI(rect,prop,label), GetPropertyHeight()
               attribute, fieldInfo, preferredLabel

SerializedObject: Update(), ApplyModifiedProperties(), FindProperty()
MenuItem:      [MenuItem("Path", validate, priority)], % # & ^ _ shortcuts
Gizmos:        DrawLine/Sphere/WireSphere/Cube/WireCube/Ray/Mesh/Icon, color, matrix
Handles:       PositionHandle/RotationHandle/ScaleHandle/FreeMoveHandle/RadiusHandle
               DrawLine/DrawWireDisc/Label, BeginGUI/EndGUI, color, matrix
AssetDatabase: CreateAsset, LoadAssetAtPath<T>, FindAssets, SaveAssets, Refresh
```

---

## Related Skills

- **unity-foundations** -- Project structure, assembly definitions, Editor folders
- **unity-scripting** -- MonoBehaviour lifecycle, SerializeField, ScriptableObject
- **unity-ui** -- UI Toolkit fundamentals, VisualElement, UXML, USS

---

## Additional Resources

- [Custom Editor Windows (Manual)](https://docs.unity3d.com/6000.3/Documentation/Manual/editor-EditorWindows.html)
- [Custom Editors (Manual)](https://docs.unity3d.com/6000.3/Documentation/Manual/editor-CustomEditors.html)
- [Property Drawers (Manual)](https://docs.unity3d.com/6000.3/Documentation/Manual/editor-PropertyDrawers.html)
- [Editor API](https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Editor.html)
- [EditorWindow API](https://docs.unity3d.com/6000.3/Documentation/ScriptReference/EditorWindow.html)
- [PropertyDrawer API](https://docs.unity3d.com/6000.3/Documentation/ScriptReference/PropertyDrawer.html)
- [AssetDatabase API](https://docs.unity3d.com/6000.3/Documentation/ScriptReference/AssetDatabase.html)
- [SerializedObject API](https://docs.unity3d.com/6000.3/Documentation/ScriptReference/SerializedObject.html)
- [MenuItem API](https://docs.unity3d.com/6000.3/Documentation/ScriptReference/MenuItem.html)
- [Gizmos API](https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Gizmos.html)
- [Handles API](https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Handles.html)
Files in this package (4)
  • SKILL.md 14 KB
  • references/custom-inspectors.md 10 KB
  • references/editor-windows.md 9 KB
  • references/property-drawers.md 10 KB

Versions

The database has no other skills named unity-editor-tools.

Identical content appears in 2 other GitHub folders. We show one copy with the highest score.

Database snapshot: 13.11.2026 · package version c55f87f7f0c5 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100uw-unity-editor-tools
    Generate custom editor tooling including Custom Inspectors, PropertyDrawers, EditorWindows, Gizmos, and Handles. Use when building designer-facing tools, spatial visualization, batch operations, or custom component UIs. Triggers on requests like "create a custom inspector", "add…
  • 100unity-editor-tooling
    Unity Editor scripting — custom Inspectors, PropertyDrawers, EditorWindow, MenuItems, asset post-processors, Editor Coroutines, automated builds via `-batchmode -executeMethod`. USE WHEN: building tools for designers, custom Inspector UI, gizmos, scene validators, asset import…
  • 98unity-editor-tool-developer
    Use when Codex should act as the Unity Editor Tool Developer specialist from Agency Agents. Unity editor automation specialist - Masters custom EditorWindows, PropertyDrawers, AssetPostprocessors, ScriptedImporters, and pipeline automation that saves teams hours per week
  • 90unity-editor-automation
    Use when the task is to automate editor workflows with safe, scoped Unity Editor scripts.
  • 95unity-mcp-skill
    Orchestrate Unity Editor via MCP (Model Context Protocol) tools and resources. Use when working with Unity projects through MCP for Unity - creating/modifying GameObjects, editing scripts, managing scenes, running tests, or any Unity Editor automation. Provides best practices,…
  • 90unity-verification
    Unity verification rules. Use when checking that a Unity change compiles or works, running Unity tests, building a player, running C# in the Editor, classifying Unity involvement for issue triage or selection, or when Unity cannot run here or the editor is locked.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.