Unity-Technologies/UnityCsReference · error · ArgumentException

Specify exactly one edge

Error message

Specify exactly one edge

What it means

Thrown by a SplitView helper that computes the hover/drag rectangle for a given view edge (Left, Right, Top, Bottom). The switch falls through to a default case when the supplied ViewEdge value does not match any known edge, meaning exactly one valid edge was not provided. It indicates either an invalid enum value or an enum that has been extended without updating this switch.

Source

Thrown at Editor/Mono/GUI/SplitView.cs:54

            FitsHorizontal = Left | Right,
            Before = Top | Left, // "Before" in SplitView children
            After = Bottom | Right // "After" in SplitView children
        }

        private Rect RectFromEdge(Rect rect, ViewEdge edge, float thickness, float offset)
        {
            switch (edge)
            {
                case ViewEdge.Left:
                    return new Rect(rect.x - offset, rect.y, thickness, rect.height);
                case ViewEdge.Right:
                    return new Rect(rect.xMax - thickness + offset, rect.y, thickness, rect.height);
                case ViewEdge.Top:
                    return new Rect(rect.x, rect.y - offset, rect.width, thickness);
                case ViewEdge.Bottom:
                    return new Rect(rect.x, rect.yMax - thickness + offset, rect.width, thickness);
                default:
                    throw new ArgumentException("Specify exactly one edge");
            }
        }

        // Extra info for dropping.
        internal class ExtraDropInfo
        {
            public bool rootWindow;
            public ViewEdge edge;
            public int index;
            public ExtraDropInfo(bool rootWindow, ViewEdge edge, int index)
            {
                this.rootWindow = rootWindow;
                this.edge = edge;
                this.index = index;
            }
        }

        SplitterState splitState = null;

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Ensure the ViewEdge value passed is one of Left, Right, Top, or Bottom before calling the helper.
  2. If you added a new ViewEdge member, add the corresponding case branch returning the correct Rect.
  3. Validate/normalize the enum at the call site and fall back to a known edge (e.g. Left) instead of forwarding an unknown value.

Example fix

// before
var r = GetDropRect(edge, rect, thickness, offset); // edge may be invalid

// after
ViewEdge safeEdge = (edge == ViewEdge.Left || edge == ViewEdge.Right || edge == ViewEdge.Top || edge == ViewEdge.Bottom)
    ? edge
    : ViewEdge.Left;
var r = GetDropRect(safeEdge, rect, thickness, offset);
Defensive patterns

Strategy: validation

Validate before calling

bool IsValidEdge(ViewEdge e) => e == ViewEdge.Left || e == ViewEdge.Right || e == ViewEdge.Top || e == ViewEdge.Bottom;

Type guard

static bool IsDefinedEdge(ViewEdge edge) => Enum.IsDefined(typeof(ViewEdge), edge) && (edge == ViewEdge.Left || edge == ViewEdge.Right || edge == ViewEdge.Top || edge == ViewEdge.Bottom);

Prevention

When it happens

Trigger: Calling the edge-rect helper with a ViewEdge value outside {Left, Right, Top, Bottom} — e.g. casting an arbitrary integer to ViewEdge, passing an uninitialized field, or a new enum member added to ViewEdge without a matching case here.

Common situations: Extending the ViewEdge enum with a new edge type and forgetting to handle it in SplitView; a serialization/deserialization desync producing an out-of-range enum value; default(ViewEdge) used before assignment when '0' is not a valid edge.

Related errors


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