{"record":{"id":"1c13608841c3a90b","repo":"Unity-Technologies/UnityCsReference","slug":"object-is-not-a-editorbuildsettingsscene","errorCode":null,"errorMessage":"object is not a EditorBuildSettingsScene","messagePattern":"object is not a EditorBuildSettingsScene","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/EditorBuildSettings.bindings.cs","lineNumber":63,"sourceCode":"\n        public bool enabled { get { return m_enabled; } set { m_enabled = value; } }\n        public string path { get { return m_path; } set { m_path = value.Replace(\"\\\\\", \"/\"); } }\n        public GUID guid { get { return m_guid; } set { m_guid = value; } }\n        public static string[] GetActiveSceneList(EditorBuildSettingsScene[] scenes)\n        {\n#pragma warning disable UA2001 // The Banned API Analyzer produces compile errors for any new Linq code. This pre-existing usage has been suppressed, but should be rewritten if possible.\n            return scenes.Where(scene => scene.enabled && !string.IsNullOrEmpty(scene.path)).Select(scene => scene.path).ToArray();\n#pragma warning restore UA2001\n        }\n\n        public int CompareTo(object obj)\n        {\n            if (obj is EditorBuildSettingsScene)\n            {\n                EditorBuildSettingsScene temp = (EditorBuildSettingsScene)obj;\n                return temp.path.CompareTo(path);\n            }\n            throw new ArgumentException(\"object is not a EditorBuildSettingsScene\");\n        }\n\n        [RequiredByNativeCode, UsedImplicitly]\n        private static void DeconstructArrayElement(EditorBuildSettingsScene[] arr, int index, out bool enabled, out string path, out GUID guid)\n        {\n            var item = arr[index];\n            enabled = item.enabled;\n            path = item.path;\n            guid = item.guid;\n        }\n    }\n\n    [global::UnityEngine.NativeClass(\"EditorBuildSettings\", PersistentTypeId = 1045)]\n    [NativeHeader(\"Editor/Src/EditorBuildSettings.h\")]\n    public partial class EditorBuildSettings : UnityEngine.Object\n    {\n        private EditorBuildSettings() {}\n        [AutoStaticsCleanupOnCodeReload]","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/EditorBuildSettings.bindings.cs#L45-L81","documentation":"Thrown by EditorBuildSettingsScene.CompareTo when the argument is not an EditorBuildSettingsScene. The method implements IComparable.CompareTo(object) but only handles its own type; any other type (or a subtype the cast misses) yields ArgumentException. This is the classic IComparable contract violation — CompareTo must accept object and reject incompatible types cleanly.","triggerScenarios":"Placing EditorBuildSettingsScene instances into a Sort() call alongside other types, or passing a boxed value of a different type to CompareTo directly. Also triggered by generic containers/sorters that call CompareTo(object) without type narrowing.","commonSituations":"Custom build-settings UI that sorts a heterogeneous list; interop with arrays typed as object[]; reflection-driven code invoking CompareTo with the wrong runtime type.","solutions":["Ensure the collection contains only EditorBuildSettingsScene before sorting; filter or separate by type.","If you must compare mixed types, implement a custom IComparer<object> that checks type first and returns 0/orders by type.","Call CompareTo only with values you have type-checked: if (obj is EditorBuildSettingsScene other) ... else throw explicitly."],"exampleFix":"// before\nArray.Sort(mixedObjects); // contains non-scene items\n// after\nvar scenes = mixedObjects.OfType<EditorBuildSettingsScene>().ToArray();\nArray.Sort(scenes, (a, b) => string.Compare(a.path, b.path, StringComparison.Ordinal));","handlingStrategy":"type-guard","validationCode":"if (obj is EditorBuildSettingsScene other)\n    return other.path.CompareTo(path);\nthrow new ArgumentException($\"Expected EditorBuildSettingsScene, got {obj?.GetType()}\");","typeGuard":"static bool IsEditorBuildSettingsScene(object o) => o is EditorBuildSettingsScene;","tryCatchPattern":null,"preventionTips":["Keep EditorBuildSettingsScene collections homogeneous.","Prefer a typed IComparer<EditorBuildSettingsScene> over the non-generic CompareTo(object).","Type-check before invoking IComparable.CompareTo on object-typed inputs."],"tags":["editor","build-settings","icomparable","type-mismatch","sorting"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}