Unity-Technologies/UnityCsReference · error · ArgumentException

Editor type '{editorType}' does not derive from UnityEditor.

Error message

Editor type '{editorType}' does not derive from UnityEditor.Editor

What it means

CreateEditorWithContext validates that a caller-supplied editorType is a subclass of UnityEditor.Editor before forwarding to the native CreateEditorWithContextInternal. Passing any other type (including Editor itself is allowed only via IsSubclassOf semantics — note IsSubclassOf excludes the base), or a non-Editor type, throws ArgumentException.

Source

Thrown at Editor/Mono/Inspector/Editor.cs:617

            get
            {
                GetSerializedObjectInternal();
                return m_EnabledProperty;
            }
        }

        internal virtual void PostSerializedObjectCreation() {}

        internal bool isInspectorDirty
        {
            get { return m_IsDirty != 0; }
            set { m_IsDirty = value ? 1 : 0; }
        }

        public static Editor CreateEditorWithContext(UnityObject[] targetObjects, UnityObject context, [UnityEngine.Internal.DefaultValue("null")] Type editorType)
        {
            if (editorType != null && !editorType.IsSubclassOf(typeof(Editor)))
                throw new ArgumentException($"Editor type '{editorType}' does not derive from UnityEditor.Editor", "editorType");

            return CreateEditorWithContextInternal(targetObjects, context, editorType);
        }

        [ExcludeFromDocs]
        public static Editor CreateEditorWithContext(UnityObject[] targetObjects, UnityObject context)
        {
            Type editorType = null;
            return CreateEditorWithContext(targetObjects, context, editorType);
        }

        public static void CreateCachedEditorWithContext(UnityObject targetObject, UnityObject context, Type editorType, ref Editor previousEditor)
        {
            CreateCachedEditorWithContext(new[] {targetObject}, context, editorType, ref previousEditor);
        }

        public static void CreateCachedEditorWithContext(UnityObject[] targetObjects, UnityObject context, Type editorType, ref Editor previousEditor)
        {

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Ensure editorType is null or a concrete type derived from UnityEditor.Editor (not Editor itself).
  2. Guard with editorType == null || editorType.IsSubclassOf(typeof(Editor)) before calling.
  3. Resolve the type via reflection and validate it is an Editor subclass before passing.
  4. If you want default editor selection, pass null for editorType rather than typeof(Editor).

Example fix

// before
var ed = Editor.CreateEditorWithContext(targets, null, someType); // throws if someType isn't an Editor subclass

// after
if (someType == null || someType.IsSubclassOf(typeof(Editor)))
    ed = Editor.CreateEditorWithContext(targets, null, someType);
Defensive patterns

Strategy: type-guard

Validate before calling

if (editorType != null && !editorType.IsSubclassOf(typeof(Editor)))
    throw new InvalidOperationException($"{editorType} must derive from Editor.");
var ed = Editor.CreateEditorWithContext(targets, context, editorType);

Type guard

static bool IsValidEditorType(Type t) => t == null || t.IsSubclassOf(typeof(Editor));

Prevention

When it happens

Trigger: Calling Editor.CreateEditorWithContext(targets, context, editorType) with editorType that is null-safe but, when non-null, must be a strict subclass of Editor. Passing typeof(Editor), a non-Editor class, or a value/interface type triggers it.

Common situations: Dynamically selecting an editor type by name/reflection and passing a type that isn't a concrete Editor subclass. Passing typeof(Editor) expecting it to work (IsSubclassOf returns false for the base). Type-resolution returning null unexpectedly — but null is actually allowed and routes to default editor selection.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/3eac1ac8c4bfc2df. Report an issue: GitHub.