{"record":{"id":"3eac1ac8c4bfc2df","repo":"Unity-Technologies/UnityCsReference","slug":"editor-type-editortype-does-not-derive-from-un","errorCode":null,"errorMessage":"Editor type '{editorType}' does not derive from UnityEditor.Editor","messagePattern":"Editor type '(.+?)' does not derive from UnityEditor\\.Editor","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Inspector/Editor.cs","lineNumber":617,"sourceCode":"            get\n            {\n                GetSerializedObjectInternal();\n                return m_EnabledProperty;\n            }\n        }\n\n        internal virtual void PostSerializedObjectCreation() {}\n\n        internal bool isInspectorDirty\n        {\n            get { return m_IsDirty != 0; }\n            set { m_IsDirty = value ? 1 : 0; }\n        }\n\n        public static Editor CreateEditorWithContext(UnityObject[] targetObjects, UnityObject context, [UnityEngine.Internal.DefaultValue(\"null\")] Type editorType)\n        {\n            if (editorType != null && !editorType.IsSubclassOf(typeof(Editor)))\n                throw new ArgumentException($\"Editor type '{editorType}' does not derive from UnityEditor.Editor\", \"editorType\");\n\n            return CreateEditorWithContextInternal(targetObjects, context, editorType);\n        }\n\n        [ExcludeFromDocs]\n        public static Editor CreateEditorWithContext(UnityObject[] targetObjects, UnityObject context)\n        {\n            Type editorType = null;\n            return CreateEditorWithContext(targetObjects, context, editorType);\n        }\n\n        public static void CreateCachedEditorWithContext(UnityObject targetObject, UnityObject context, Type editorType, ref Editor previousEditor)\n        {\n            CreateCachedEditorWithContext(new[] {targetObject}, context, editorType, ref previousEditor);\n        }\n\n        public static void CreateCachedEditorWithContext(UnityObject[] targetObjects, UnityObject context, Type editorType, ref Editor previousEditor)\n        {","sourceCodeStart":599,"sourceCodeEnd":635,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Inspector/Editor.cs#L599-L635","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure editorType is null or a concrete type derived from UnityEditor.Editor (not Editor itself).","Guard with editorType == null || editorType.IsSubclassOf(typeof(Editor)) before calling.","Resolve the type via reflection and validate it is an Editor subclass before passing.","If you want default editor selection, pass null for editorType rather than typeof(Editor)."],"exampleFix":"// before\nvar ed = Editor.CreateEditorWithContext(targets, null, someType); // throws if someType isn't an Editor subclass\n\n// after\nif (someType == null || someType.IsSubclassOf(typeof(Editor)))\n    ed = Editor.CreateEditorWithContext(targets, null, someType);","handlingStrategy":"type-guard","validationCode":"if (editorType != null && !editorType.IsSubclassOf(typeof(Editor)))\n    throw new InvalidOperationException($\"{editorType} must derive from Editor.\");\nvar ed = Editor.CreateEditorWithContext(targets, context, editorType);","typeGuard":"static bool IsValidEditorType(Type t) => t == null || t.IsSubclassOf(typeof(Editor));","tryCatchPattern":null,"preventionTips":["Pass null for editorType when you want the default editor; do not pass typeof(Editor).","Validate reflected/resolved types with IsSubclassOf(typeof(Editor)) before calling.","Log a clear error if dynamic type selection yields a non-Editor type."],"tags":["editor","type-validation","reflection","argument"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}