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.
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)
Solutions
- Return early when content is null instead of calling Show.
- Ensure the content factory never returns null; provide a fallback content.
- 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
- Null-check popup content before Show; treat null as 'nothing to display'.
- Ensure content factories return a non-null instance or a documented fallback.
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
- Parameter selected must be of type System.Enum
- Calling GUISkin.current outside OnGUI. This might break the
- Cannot select range when not in multi select mode.
- The path is null
- prefabInstanceRoots
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/482c1d2f2979baa5.
Report an issue: GitHub.