stride3d/stride · error · InvalidOperationException

The given (Name= ) is not a child of (Name= ).

Error message

The given {childPart.GetType().Name} (Name={childPart.Name}) is not a child of {nameof(Panel)} (Name={panel.Name}).

What it means

Thrown by UIAssetPropertyGraph.RemoveChildPartFromParentPart when, during asset reparenting, the given part is not present in the target Panel's Children collection. The code casts the parent to Panel, calls Children.IndexOf(childPart), and throws InvalidOperationException if the index is -1, so the node graph can not be updated consistently.

Solutions

  1. Verify childPart.Parent points at the same panel you pass as parentPart before removing.
  2. Check IndexOf(childPart) >= 0 on panel.Children yourself and skip the removal if it is not found.
  3. Reload the UI asset if the in-memory hierarchy and node graph have drifted apart.

Example fix

// before
panel.Children.Remove(child);
parentGraph.RemoveChildPartFromParentPart(panel, child);

// after
var index = panel.Children.IndexOf(child);
if (index >= 0)
{
    panel.Children.RemoveAt(index);
    parentGraph.RemoveChildPartFromParentPart(panel, child);
}
Defensive patterns

Strategy: validation

Validate before calling

if (parentPart is Panel panel && panel.Children.IndexOf(childPart) >= 0)
    RemoveChildPartFromParentPart(parentPart, childPart);

Type guard

bool CanRemove(Part parent, Part child) => parent is Panel p && p.Children.Contains(child);

Prevention

When it happens

Trigger: Calling RemoveChildPartFromParentPart with a parentPart that is a Panel whose Children list does not contain childPart; typically when the child was already removed, was never added to this parent, or the parent is a different panel instance than the one holding the child.

Common situations: Editing a UI hierarchy in Game Studio where two editors operate on stale copies; custom asset scripts that reparent elements after having already detached them; deserialized assets whose Children indices differ from the in-memory node graph.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/71ed634450d110dd. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Assets/Quantum/UIAssetPropertyGraph.cs:99

        /// <inheritdoc/>
        protected override void RemoveChildPartFromParentPart(UIElement parentPart, UIElement childPart)
        {
            var control = parentPart as ContentControl;
            if (control != null)
            {
                var node = Container.NodeContainer.GetOrCreateNode(control)[nameof(ContentControl.Content)];
                if (childPart != node.Retrieve())
                    throw new InvalidOperationException($"The given {childPart.GetType().Name} (Name={childPart.Name}) is not the current content of {nameof(ContentControl)} (Name={control.Name}).");

                node.Update(null);
                return;
            }
            var panel = parentPart as Panel;
            if (panel != null)
            {
                var index = panel.Children.IndexOf(childPart);
                if (index == -1)
                    throw new InvalidOperationException($"The given {childPart.GetType().Name} (Name={childPart.Name}) is not a child of {nameof(Panel)} (Name={panel.Name}).");

                var node = Container.NodeContainer.GetOrCreateNode(panel)[nameof(Panel.Children)].Target;
                node.Remove(childPart, new NodeIndex(index));
                return;
            }
            throw new NotSupportedException();
        }

        /// <inheritdoc/>
        protected override Guid GetIdFromChildPart(object part)
        {
            return ((UIElement)part).Id;
        }

        /// <inheritdoc/>
        protected override bool ShouldAddNewPartFromBase(AssetCompositeHierarchyPropertyGraph<UIElementDesign, UIElement> baseAssetGraph, UIElementDesign newPart, UIElement newPartParent, Guid instanceId)
        {
            if (!base.ShouldAddNewPartFromBase(baseAssetGraph, newPart, newPartParent, instanceId))

View on GitHub (pinned to 96fad776d2)