Unity-Technologies/UnityCsReference · error · LayoutException

Error while reading window layout: no main window found

Error message

Error while reading window layout: no main window found

What it means

After loading a layout, if no window with ShowMode.MainWindow was found among the deserialized objects, and the caller did not opt out of main-window support via LoadWindowLayoutFlags.NoMainWindowSupport, the editor throws LayoutException. A valid editor session fundamentally requires a main window, so loading a layout without one is a fatal configuration error.

Source

Thrown at Editor/Mono/GUI/WindowLayout.cs:1446

                    // Delete the current mainWindow so that we can load back the previous layout otherwise every attemp at loading a layout will fail.
                    if (mainWindow.rootView == null || !mainWindow.rootView)
                    {
                        mainWindow.Close();
                        UnityObject.DestroyImmediate(mainWindow, true);
                        throw new LayoutException("Error while reading window layout: no root view on main window.");
                    }

                    mainWindow.Show(mainWindow.showMode, loadPosition: true, displayImmediately: true, setFocus: true);
                    if (mainWindowToSetSize && mainWindow.maximized != mainWindowMaximized)
                        mainWindow.ToggleMaximize();

                    // Make sure to restore the save to layout flag when loading a layout from a file.
                    if (flags.HasFlag(LoadWindowLayoutFlags.KeepMainWindow))
                        mainWindow.m_DontSaveToLayout = false;
                }
                else if (!flags.HasFlag(LoadWindowLayoutFlags.NoMainWindowSupport))
                {
                    throw new LayoutException("Error while reading window layout: no main window found");
                }

                // Show other windows
                for (int i = 0; i < newWindows.Count; i++)
                {
                    if (newWindows[i] == null)
                        continue;

                    EditorWindow win = newWindows[i] as EditorWindow;
                    if (win)
                        win.minSize = win.minSize; // Causes minSize to be propagated upwards to parents!

                    ContainerWindow containerWindow = newWindows[i] as ContainerWindow;
                    if (containerWindow && containerWindow != mainWindow)
                    {
                        containerWindow.Show(containerWindow.showMode, loadPosition: false, displayImmediately: true, setFocus: true);
                        if (flags.HasFlag(LoadWindowLayoutFlags.NoMainWindowSupport))
                        {

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Use a layout file that includes a main window, or pass LoadWindowLayoutFlags.NoMainWindowSupport if auxiliary-only loading is intended.
  2. Fall back to the default layout which always defines a main window.
  3. Regenerate the layout by saving from a normal editor session.
  4. Verify the layout was not produced by a stripped/editor-batchmode configuration.
Defensive patterns

Strategy: validation

Validate before calling

// for auxiliary-only loads, opt out of main-window requirement
LoadWindowLayout(path, LoadWindowLayoutFlags.NoMainWindowSupport);

Try / catch

try { LoadWindowLayout(path, flags); }
catch (LayoutException ex) when (ex.Message.Contains("no main window found"))
{ LoadDefaultWindowLayout(); }

Prevention

When it happens

Trigger: Loading a layout file that contains only floating/secondary windows (no MainWindow); a layout saved in a non-standard mode; passing a flag set that does not include NoMainWindowSupport when intentionally loading an auxiliary-only layout.

Common situations: Saving a layout from a build/configuration without a main window; corrupt deserialization dropping the main window entry; misuse of the layout-loading API.

Related errors


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