{"record":{"id":"c2c37c1959bbc0f9","repo":"Unity-Technologies/UnityCsReference","slug":"target-overlay-has-an-invalid-container","errorCode":null,"errorMessage":"Target overlay has an invalid container","messagePattern":"Target overlay has an invalid container","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Overlays/OverlayPlacement.cs","lineNumber":140,"sourceCode":"                index = sectionCount;\n            }\n\n            this.container.InsertOverlay(this, section, index, hint);\n\n            floating = container is FloatingOverlayContainer;\n\n            if (!existsInContainer)\n                RebuildContent(false);\n\n            dockingCompleted?.Invoke(container);\n\n            return true;\n        }\n\n        internal bool DockBefore(Overlay target)\n        {\n            if (target.container == null)\n                throw new ArgumentException(\"Target overlay has an invalid container\", nameof(target));\n\n            var targetContainer = target.container;\n            targetContainer.GetOverlayIndex(target, out OverlayContainerSection section, out var targetIndex);\n            if (container == targetContainer)\n            {\n                container.GetOverlayIndex(this, out OverlayContainerSection thisSection, out var thisIndex);\n                if (thisIndex < targetIndex && thisSection == section)\n                    targetIndex--;\n            }\n\n            return DockAt(targetContainer, section, targetIndex);\n        }\n\n        internal bool DockAfter(Overlay target)\n        {\n            if (target.container == null)\n                throw new ArgumentException(\"Target overlay has an invalid container\", nameof(target));\n","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Overlays/OverlayPlacement.cs#L122-L158","documentation":"Thrown by OverlayPlacement.DockBefore when the target Overlay has a null container. Docking logic needs both overlays to belong to the same OverlayContainer to compute indices; an undocked target cannot be a dock reference.","triggerScenarios":"Calling DockBefore(target) where target.container == null — target is floating/unparented.","commonSituations":"Target overlay was removed from its container but the reference is still held; ordering dock calls before the target has been placed into a container; UI state desync after a layout rebuild.","solutions":["Ensure the target overlay is docked into a container before calling DockBefore.","Check target.container != null before invoking.","Re-add the target to a container (e.g., overlayCanvas) first."],"exampleFix":"// before\nthis.DockBefore(floatingTarget); // throws\n// after\nif (floatingTarget.container != null)\n    this.DockBefore(floatingTarget);\nelse\n    floatingTarget.DockInto(this.container);","handlingStrategy":"validation","validationCode":"if (target.container != null) this.DockBefore(target);","typeGuard":"static bool IsDocked(Overlay o) => o.container != null;","tryCatchPattern":null,"preventionTips":["Check target.container != null before docking.","Ensure overlays are placed into a container before reorder operations."],"tags":["unity","overlays","ui","docking","validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}