Unity-Technologies/UnityCsReference · error · InvalidOperationException

Unhandled enum {dropPosition}

Error message

Unhandled enum {dropPosition}

What it means

Thrown by the DropPosition switch inside GetTransformParentForDrop when the dropPosition enum value is not Upon, Below, or Above. This default branch guards against an unhandled enum case so the parent resolution never silently returns undefined behavior.

Source

Thrown at Editor/Mono/GUI/TreeView/AssetOrGameObjectTreeViewDragging.cs:302

                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);
                }
            }
            else
            {
                // Find transform parent from Scene
                var scene = EditorSceneManager.GetSceneByHandle(SceneHandle.From(gameObjectOrSceneInstanceID));
                var subSceneInfo = SubSceneGUI.GetSubSceneInfo(scene);
                if (subSceneInfo.isValid)
                    return subSceneInfo.transform;
                return null; // root scene has no transform parent
            }
        }

        static bool IsDropTargetUserModifiable(GameObjectTreeViewItem targetItem, DropPosition dropPos)
        {
            if (targetItem.isSceneHeader && !targetItem.scene.isLoaded)
                return false;

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Map the dropPosition to one of Upon/Below/Above before calling the helper.
  2. If a new DropPosition member was added, implement its transform-parent logic here.
  3. Reject the drag with DragAndDropVisualMode.None for unrecognized positions instead of calling through.

Example fix

// before
var p = GetTransformParentForDrop(id, dropPosition);

// after
DropPosition pos = (dropPosition == DropPosition.Upon || dropPosition == DropPosition.Below || dropPosition == DropPosition.Above)
    ? dropPosition
    : DropPosition.Below;
var p = GetTransformParentForDrop(id, pos);
Defensive patterns

Strategy: validation

Validate before calling

bool validPos = dropPosition == DropPosition.Upon || dropPosition == DropPosition.Below || dropPosition == DropPosition.Above;

Type guard

static bool IsHandledPosition(DropPosition p) => p == DropPosition.Upon || p == DropPosition.Below || p == DropPosition.Above;

Prevention

When it happens

Trigger: Passing a DropPosition value outside the handled set (e.g. a new enum member, an invalid cast, or default(DropPosition) when '0' is unmapped).

Common situations: Extending DropPosition with a new mode without updating this switch; deserialization producing an out-of-range value.

Related errors


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