Unity-Technologies/UnityCsReference · error · ArgumentNullException

windowContent

Error message

windowContent

What it means

PopupWindowWithoutFocus.Show throws ArgumentNullException(nameof(windowContent)) when the PopupWindowContent argument is null. The popup requires a content object to render, so a null content is rejected at the boundary rather than opening an empty window.

Solutions

  1. Return early when content is null instead of calling Show.
  2. Ensure the content factory never returns null; provide a fallback content.
  3. Null-check at the call site before invoking Show.

Example fix

// before
PopupWindowWithoutFocus.Show(rect, content);
// after
if (content != null)
    PopupWindowWithoutFocus.Show(rect, content);
Defensive patterns

Strategy: type-guard

Validate before calling

if (windowContent != null)
    PopupWindowWithoutFocus.Show(rect, windowContent);

Type guard

static bool HasContent(PopupWindowContent c) => c != null;

Prevention

When it happens

Trigger: Calling Show with a PopupWindowContent that evaluated to null (a factory returned null, a conditional content path was skipped, or a field was never assigned).

Common situations: Conditional popup content that returns null when there is nothing to show; refactoring that drops the content argument; passing a not-yet-constructed content.

Related errors


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

Appendix: source

Thrown at Editor/Mono/GUI/PopupWindowWithoutFocus.cs:29

using Unity.Scripting.LifecycleManagement;

namespace UnityEditor
{
    partial class PopupWindowWithoutFocus : PopupWindow
    {
        [AutoStaticsCleanupOnCodeReload]
        static PopupWindowWithoutFocus s_PopupWindowWithoutFocus;
        bool hasBeenFocused = false;

        public new static void Show(Rect activatorRect, PopupWindowContent windowContent)
        {
            Show(activatorRect, windowContent, null);
        }

        internal new static void Show(Rect activatorRect, PopupWindowContent windowContent, PopupLocation[] locationPriorityOrder)
        {
            if (windowContent == null)
                throw new System.ArgumentNullException(nameof(windowContent));

            if (s_PopupWindowWithoutFocus != null)
            {
                s_PopupWindowWithoutFocus.Close();
                s_PopupWindowWithoutFocus = null;
            }

            if (ShouldShowWindow(activatorRect))
            {
                if (s_PopupWindowWithoutFocus == null)
                    s_PopupWindowWithoutFocus = CreateInstance<PopupWindowWithoutFocus>();

                s_PopupWindowWithoutFocus.Init(activatorRect, windowContent, locationPriorityOrder, ShowMode.PopupMenu, false);
            }
            else
            {
                windowContent.OnClose();
            }

View on GitHub (pinned to 225b0fbdb5)