{"record":{"id":"01bc00833389cb51","repo":"stride3d/stride","slug":"entity-shouldn-t-have-a-parent","errorCode":null,"errorMessage":"Entity shouldn't have a parent.","messagePattern":"Entity shouldn't have a parent\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Engine/Engine/EntityManager.cs","lineNumber":223,"sourceCode":"                        processor.Draw(context);\n                    }\n                }\n            }\n\n            flexibleProcessors.Draw(context);\n        }\n\n        /// <summary>\n        /// Adds the entity.\n        /// If the <see cref=\"Entity\" /> has a parent, its parent should be added (or <see cref=\"TransformComponent.Children\" />) should be used.\n        /// </summary>\n        /// <param name=\"entity\">The entity.</param>\n        /// <exception cref=\"System.ArgumentException\">Entity shouldn't have a parent.;entity</exception>\n        internal void Add(Entity entity)\n        {\n            // Entity can't be a root because it already has a parent?\n            if (entity.Transform != null && entity.Transform.Parent != null)\n                throw new ArgumentException(\"Entity shouldn't have a parent.\", nameof(entity));\n\n            InternalAddEntity(entity);\n        }\n\n        /// <summary>\n        /// Adds the specified entity.\n        /// </summary>\n        /// <param name=\"entity\">The entity to add.</param>\n        internal void InternalAddEntity(Entity entity)\n        {\n            // Already added?\n            if (entities.Contains(entity))\n                return;\n\n            if (entity.EntityManager != null)\n            {\n                throw new InvalidOperationException(\"Cannot add an entity to this entity manager when it is already used by another entity manager\");\n            }","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Engine/Engine/EntityManager.cs#L205-L241","documentation":"EntityManager.Add registers an entity as a root entity in the manager. It throws ArgumentException when the entity's Transform has a Parent, because entities with a parent are not roots — they belong to the hierarchy under their parent, not directly to the manager's root set.","triggerScenarios":"Calling entityManager.Add(entity) where entity.Transform.Parent != null, i.e. the entity was already added as a child of another entity.","commonSituations":"Re-adding an entity that is a child in a scene hierarchy; moving code that assumed flat entity lists into a parented scene; scripts adding child entities to the manager directly.","solutions":["Only add root entities (Transform.Parent == null) to the manager","To relocate an entity, remove it from its current parent first (entity.Transform.Parent = null) or reparent via Transform.Parent","Check entity.Transform?.Parent before calling Add"],"exampleFix":"// before\nentityManager.Add(childEntity);\n// after\nif (childEntity.Transform?.Parent == null)\n    entityManager.Add(childEntity);\nelse\n    childEntity.Transform.Parent = null; // detach first if relocation is intended","handlingStrategy":"validation","validationCode":"if (entity.Transform?.Parent != null) return; // not a root, skip Add\nentityManager.Add(entity);","typeGuard":"static bool IsRootEntity(Stride.Engine.Entity e) => e?.Transform?.Parent == null;","tryCatchPattern":"try { entityManager.Add(entity); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"shouldn't have a parent\")) { /* reparent or skip */ }","preventionTips":["Only add root entities to the manager; children live under their parent","Reparent via Transform.Parent instead of manager Add/Remove","Check Parent before hierarchy-manipulating calls"],"tags":["csharp","stride","hierarchy","invalid-state"],"backgroundTag":"invalid-state-transition","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"}