{"record":{"id":"8dd98d9f989af246","repo":"stride3d/stride","slug":"entity-is-not-contained-in-a-hierarchy","errorCode":null,"errorMessage":"{entity} is not contained in a hierarchy.","messagePattern":"(.+?) is not contained in a hierarchy\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/ViewModels/EntityHierarchyEditorViewModel.cs","lineNumber":224,"sourceCode":"\n            // set selection to new copied elements.\n            SelectedItems.AddRange(duplicatedAssets);\n\n            return duplicatedAssets;\n        }\n\n        [NotNull]\n        public static EntityHierarchyRootViewModel GetRoot([NotNull] EntityViewModel entity)\n        {\n            if (entity == null) throw new ArgumentNullException(nameof(entity));\n            var rootEntity = entity;\n            EntityViewModel parentEntity;\n            while ((parentEntity = rootEntity.TransformParent as EntityViewModel) != null)\n            {\n                rootEntity = parentEntity;\n            }\n            if (rootEntity.TransformParent == null)\n                throw new InvalidOperationException($\"{entity} is not contained in a hierarchy.\");\n            return (EntityHierarchyRootViewModel)rootEntity.TransformParent;\n        }\n\n        public void UpdateTransformations([NotNull] IReadOnlyDictionary<AbsoluteId, TransformationTRS> transformations)\n        {\n            using (var transaction = UndoRedoService.CreateTransaction())\n            {\n                foreach (var transformation in transformations)\n                {\n                    var element = (EntityHierarchyElementViewModel)FindPartViewModel(transformation.Key);\n                    UpdateTransformations(element, transformation.Value);\n                }\n\n                UndoRedoService.SetName(transaction, \"Update transformation\");\n            }\n        }\n\n        protected virtual void UpdateTransformations(EntityHierarchyElementViewModel element, TransformationTRS transformation)","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/ViewModels/EntityHierarchyEditorViewModel.cs#L206-L242","documentation":"EntityHierarchyEditorViewModel.GetRoot(entity) walks up TransformParent links to find the hierarchy root. If the loop ends with rootEntity.TransformParent still null, the entity is not attached to any EntityHierarchyRootViewModel, meaning it is not part of a scene hierarchy, and an InvalidOperationException is thrown.","triggerScenarios":"Calling GetRoot with an EntityViewModel whose TransformParent chain never reaches an EntityHierarchyRootViewModel — e.g. a detached or newly created entity not yet inserted into the hierarchy.","commonSituations":"Querying the hierarchy root for an entity that was created but not yet added to the scene; an entity whose parent view-model link was broken by a partial deletion.","solutions":["Ensure the entity is inserted into the entity hierarchy before calling GetRoot","Check entity.TransformParent != null (or that it belongs to a root) before calling","Re-add the detached entity to the hierarchy via the editor's insert APIs"],"exampleFix":"// before\nvar root = editorViewModel.GetRoot(entity); // throws if detached\n// after\nif (entity.TransformParent != null)\n    var root = editorViewModel.GetRoot(entity);","handlingStrategy":"type-guard","validationCode":"bool inHierarchy = entity.TransformParent != null;\nif (inHierarchy) { var root = editorViewModel.GetRoot(entity); }","typeGuard":"bool HasHierarchyRoot(EntityViewModel e) => e.TransformParent != null;","tryCatchPattern":"try { var root = editorViewModel.GetRoot(entity); }\ncatch (InvalidOperationException) { /* entity is detached from the hierarchy */ }","preventionTips":["Insert entities into the hierarchy before querying their root","Re-check TransformParent after undo/redo or delete operations"],"tags":["csharp","stride","hierarchy","entity"],"backgroundTag":"entity-not-found","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}