Unity-Technologies/UnityCsReference · error · LayoutException
Error while reading window layout: no root view on main wind
Error message
Error while reading window layout: no root view on main window.
What it means
After loading a layout, the editor requires the main window to have a valid rootView; if it is null the layout is considered missing a main window and is unrecoverable. The code destroys the broken main window and throws LayoutException so the caller can fall back to the previous/default layout. Without this, every subsequent load attempt would also fail.
Source
Thrown at Editor/Mono/GUI/WindowLayout.cs:1433
if (w is SceneHierarchyWindow || (w?.GetType() == HierarchyPreferences.HierarchyV2WindowType))
HierarchyPreferences.EnsureCorrectHierarchyIsInUse(w);
}
if (mainWindowToSetSize)
{
mainWindowToSetSize.position = mainWindowPosition;
}
// Always show main window before other windows. So that other windows can
// get their parent/owner.
if (mainWindow)
{
// If at this point the mainWindow still doesn't have a rootView, it probably means we loaded a layout without a main window.
// 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++)
{View on GitHub (pinned to 225b0fbdb5)
Solutions
- Let Unity fall back to the previous/default layout (the throw is designed to trigger that recovery).
- Replace the offending layout file with a known-good one.
- Avoid manually editing the main window entry in layout files.
- On persistent failures, delete the user's current layout settings (e.g. CurrentLayout.dwlt) to force regeneration.
Defensive patterns
Strategy: fallback
Try / catch
try { LoadWindowLayout(path, flags); }
catch (LayoutException ex) when (ex.Message.Contains("no root view on main window"))
{ LoadDefaultWindowLayout(); } Prevention
- Allow Unity to fall back to default layout when a load fails.
- Do not hand-edit main-window entries in layout files.
- Delete the stale CurrentLayout file if startup persistently fails.
When it happens
Trigger: A layout file that serializes auxiliary windows but omits/not-wires the main window's rootView; a layout from a platform/build where the main window failed to serialize its root; corrupted main-window entry.
Common situations: Loading a layout saved on a different display setup or Unity version; a half-written layout file; editor startup with a stale default layout.
Related errors
- Invalid split view data
- No parent view
- No windows found in layout.
- Error while reading window layout: no main window found
- Parameter asset is null
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/30604658be280ab6.
Report an issue: GitHub.