{"record":{"id":"717b19ab82817dce","repo":"Unity-Technologies/UnityCsReference","slug":"unexpected-unityengine-object-type-in-hierarchy-o","errorCode":null,"errorMessage":"Unexpected UnityEngine.Object type in Hierarchy {obj.GetType()}","messagePattern":"Unexpected UnityEngine\\.Object type in Hierarchy (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/AssetOrGameObjectTreeViewDragging.cs","lineNumber":285,"sourceCode":"\n                // Require all dragged objects to be valid (since native cannot filter out invalid sub scene drags currently)\n                if (SubSceneGUI.IsChildOrSameAsOtherTransform(parentForDrop, gameObject.transform))\n                    return false;\n            }\n\n            // Valid drop target for current dragged objects\n            return true;\n        }\n\n        Transform GetTransformParentForDrop(EntityId gameObjectOrSceneInstanceID, DropPosition dropPosition)\n        {\n            var obj = EditorUtility.EntityIdToObject(gameObjectOrSceneInstanceID);\n            if (obj != null)\n            {\n                // Find transform parent from GameObject\n                var go = obj as GameObject;\n                if (go == null)\n                    throw new InvalidOperationException(\"Unexpected UnityEngine.Object type in Hierarchy \" + obj.GetType());\n\n                switch (dropPosition)\n                {\n                    case DropPosition.Upon:\n                        return go.transform;\n\n                    case DropPosition.Below:\n                    case DropPosition.Above:\n                        if (go.transform.parent == null)\n                        {\n                            var subSceneInfo = SubSceneGUI.GetSubSceneInfo(go.scene);\n                            if (subSceneInfo.isValid)\n                                return subSceneInfo.transform;\n                        }\n                        return go.transform.parent;\n                    default:\n                        throw new InvalidOperationException(\"Unhandled enum \" + dropPosition);\n                }","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/AssetOrGameObjectTreeViewDragging.cs#L267-L303","documentation":"Thrown during hierarchy drag-drop when the EntityId resolves to a UnityEngine.Object that is not a GameObject. The drop logic expects to obtain a Transform parent from a GameObject; any other Object type (e.g. a material, scriptable object, or asset) is an unexpected hierarchy entry.","triggerScenarios":"Dropping onto a hierarchy node whose EntityId maps to a non-GameObject asset; a corrupted or custom hierarchy item returning an unsupported Object subtype.","commonSituations":"Custom hierarchy window extensions injecting non-GameObject items; stale EntityId references after asset import changes; scene state desync.","solutions":["Verify the drop target is a GameObject before initiating a hierarchy drop.","Skip drop targets where EditorUtility.EntityIdToObject returns a non-GameObject and show 'invalid target' feedback.","Reimport/refresh assets if EntityId mapping appears stale."],"exampleFix":"// before\nvar parent = GetTransformParentForDrop(id, pos); // id may map to non-GameObject\n\n// after\nvar obj = EditorUtility.EntityIdToObject(id);\nif (obj is GameObject go)\n    parent = go.transform;\nelse { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; return; }","handlingStrategy":"type-guard","validationCode":"var obj = EditorUtility.EntityIdToObject(id); if (!(obj is GameObject)) { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; return; }","typeGuard":"static bool IsHierarchyGameObject(EntityId id) => EditorUtility.EntityIdToObject(id) is GameObject;","tryCatchPattern":null,"preventionTips":["Validate drop targets are GameObjects in DragAndDrop acceptance logic.","Reject non-GameObject targets with visual feedback.","Refresh asset/scene state if EntityId mappings appear stale."],"tags":["unity-editor","hierarchy","drag-drop","type-check"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}