Unity-Technologies/UnityCsReference · error · ArgumentException
Cannot create more than one main window.
Error message
Cannot create more than one main window.
What it means
ArgumentException thrown by ContainerWindow.ShowPopupWithMode when the requested mode is ShowMode.MainWindow. Popups (tooltips, context menus) must not be created as the main window; the main window is a singleton created through the dedicated path, so ShowPopupWithMode explicitly refuses MainWindow.
Solutions
- Do not pass ShowMode.MainWindow to ShowPopupWithMode; use the appropriate popup/aux mode.
- Guard the mode argument and route MainWindow through the correct creation path (Show with ShowMode.MainWindow).
- Validate the mode is a popup-class mode before calling.
Example fix
// before window.ShowPopupWithMode(ShowMode.MainWindow, true); // after window.ShowPopupWithMode(ShowMode.PopupMenu, true);
Defensive patterns
Strategy: validation
Validate before calling
if (mode == ShowMode.MainWindow) throw new InvalidOperationException("Use Show for the main window, not ShowPopupWithMode.");
window.ShowPopupWithMode(mode, giveFocus); Prevention
- Never pass ShowMode.MainWindow into popup helpers.
- Route main-window creation through Show.
- Validate mode is a popup-class mode first.
When it happens
Trigger: Calling ShowPopupWithMode(ShowMode.MainWindow, giveFocus) directly. This is almost always a programming error — passing the wrong ShowMode enum value into a popup-creation routine.
Common situations: Miscopying a ShowMode argument; generic window-show helpers that forward an arbitrary mode into ShowPopupWithMode without filtering MainWindow.
Related errors
- Invalid position
- Trying to create a second main window from layout when one…
- A command with id already exists
- Android textureCompressionFormats can't be null or empty
- Attempting to assign an incorrect amount of layers to an…
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/9f6746d12375f2dc.
Report an issue: GitHub.
Appendix: source
Thrown at Editor/Mono/ContainerWindow.cs:149
internal bool isPopup => IsPopup((ShowMode)m_ShowMode);
internal void ShowPopup()
{
ShowPopupWithMode(ShowMode.PopupMenu, true);
}
internal void ShowTooltip()
{
ShowPopupWithMode(ShowMode.Tooltip, false);
}
internal void ShowPopupWithMode(ShowMode mode, bool giveFocus)
{
try
{
if (mode == ShowMode.MainWindow)
throw new ArgumentException("Cannot create more than one main window.");
m_ShowMode = (int)mode;
Internal_Show(m_PixelRect, m_ShowMode, m_MinSize, m_MaxSize);
if (m_RootView)
m_RootView.SetWindowRecurse(this);
Internal_SetTitle(m_Title);
Save();
// System windows that come from the OS (like a context menu from search) need theming
SetBackgroundColor(skinBackgroundColor);
// only set focus if mode is a popupMenu.
Internal_BringLiveAfterCreation(true, giveFocus, false);
// Fit window to screen - needs to be done after bringing the window live
position = FitRectToScreen(m_PixelRect, m_PixelRect.center, true, this);
rootView.position = new Rect(0, 0, GUIUtility.RoundToPixelGrid(m_PixelRect.width), GUIUtility.RoundToPixelGrid(m_PixelRect.height));
rootView.Reflow();View on GitHub (pinned to 225b0fbdb5)