Unity-Technologies/UnityCsReference · error · InvalidOperationException
Unexpected UnityEngine.Object type in Hierarchy {obj.GetType
Error message
Unexpected UnityEngine.Object type in Hierarchy {obj.GetType()} What it means
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.
Source
Thrown at Editor/Mono/GUI/TreeView/AssetOrGameObjectTreeViewDragging.cs:285
// Require all dragged objects to be valid (since native cannot filter out invalid sub scene drags currently)
if (SubSceneGUI.IsChildOrSameAsOtherTransform(parentForDrop, gameObject.transform))
return false;
}
// Valid drop target for current dragged objects
return true;
}
Transform GetTransformParentForDrop(EntityId gameObjectOrSceneInstanceID, DropPosition dropPosition)
{
var obj = EditorUtility.EntityIdToObject(gameObjectOrSceneInstanceID);
if (obj != null)
{
// Find transform parent from GameObject
var go = obj as GameObject;
if (go == null)
throw new InvalidOperationException("Unexpected UnityEngine.Object type in Hierarchy " + obj.GetType());
switch (dropPosition)
{
case DropPosition.Upon:
return go.transform;
case DropPosition.Below:
case DropPosition.Above:
if (go.transform.parent == null)
{
var subSceneInfo = SubSceneGUI.GetSubSceneInfo(go.scene);
if (subSceneInfo.isValid)
return subSceneInfo.transform;
}
return go.transform.parent;
default:
throw new InvalidOperationException("Unhandled enum " + dropPosition);
}View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before
var parent = GetTransformParentForDrop(id, pos); // id may map to non-GameObject
// after
var obj = EditorUtility.EntityIdToObject(id);
if (obj is GameObject go)
parent = go.transform;
else { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; return; } Defensive patterns
Strategy: type-guard
Validate before calling
var obj = EditorUtility.EntityIdToObject(id); if (!(obj is GameObject)) { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; return; } Type guard
static bool IsHierarchyGameObject(EntityId id) => EditorUtility.EntityIdToObject(id) is GameObject;
Prevention
- 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.
When it happens
Trigger: Dropping onto a hierarchy node whose EntityId maps to a non-GameObject asset; a corrupted or custom hierarchy item returning an unsupported Object subtype.
Common situations: Custom hierarchy window extensions injecting non-GameObject items; stale EntityId references after asset import changes; scene state desync.
Related errors
- Unhandled enum {dropPosition}
- ApplyPrefabAddedGameObjects requires that GameObjects share
- HierarchyProperty is deprecated. Use HierarchyIterator inste
- Unexpected resultBits Span length. The expected length of re
- ScriptableBakedReflectionSystemWrapper
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/717b19ab82817dce.
Report an issue: GitHub.