stride3d/stride · error · InvalidOperationException

The given does not correspond to any existing part.

Error message

The given {nameof(parent.Id)} does not correspond to any existing part.

What it means

PrefabEditorController.AddPart throws this InvalidOperationException when the parent part id supplied by the asset-side hierarchy cannot be resolved to an existing game-side Entity via FindPart. It guards an internal consistency assumption: you can only attach a new part's Transform under a parent that already exists in the game-side node container.

Solutions

  1. Verify the parent part exists and is loaded before calling AddPart (e.g. resolve it via FindPart yourself).
  2. Refresh the asset-side viewmodel ids so they match the current game-side hierarchy.
  3. Ensure the parent entity was loaded first (correct part-add ordering).
  4. Catch InvalidOperationException and surface a 'parent part not found' message to the user.

Example fix

// before
controller.AddPart(newPart, parentWithStaleId);
// after
if (controller.FindPart(parent.Id) != null)
    controller.AddPart(newPart, parent);
else
    logger.Warn($"Parent part {parent.Id} not loaded; skipping AddPart");
Defensive patterns

Strategy: validation

Validate before calling

if (parent == null || controller.FindPart(parent.Id) == null) throw new ArgumentException($"Parent part {parent.Id} not found");

Type guard

bool ParentExists(IPartViewModel p) => p?.Id != null && controller.FindPart(p.Id) != null;

Try / catch

try { controller.AddPart(part, parent); } catch (InvalidOperationException ex) when (ex.Message.Contains("does not correspond to any existing part")) { logger.Warn($"Parent {parent.Id} missing: {ex.Message}"); }

Prevention

When it happens

Trigger: Calling AddPart with a parent whose Id is stale, wrong, or whose corresponding entity has not yet been loaded into the game-side scene, so FindPart(parent.Id) returns null.

Common situations: Editor scripting or plugin code that holds ids from a previous prefab state; adding a part before its parent entity was loaded; desynchronized asset/game-side views after undo/redo or asset reload.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at sources/editor/Stride.Assets.Presentation/AssetEditors/PrefabEditor/Services/PrefabEditorController.cs:53

        /// <inheritdoc />
        public override Task AddPart([NotNull] EntityHierarchyElementViewModel parent, Entity assetSidePart)
        {
            EnsureAssetAccess();

            var gameSidePart = ClonePartForGameSide(parent.Asset.Asset, assetSidePart);
            return InvokeAsync(() =>
            {
                Logger.Debug($"Adding entity {assetSidePart.Id} to game-side scene");
                if (parent is PrefabRootViewModel)
                {
                    Game.LoadEntity(gameSidePart);
                }
                else
                {
                    var parentEntity = (Entity)FindPart(parent.Id);
                    if (parentEntity == null)
                        throw new InvalidOperationException($"The given {nameof(parent.Id)} does not correspond to any existing part.");

                    GameSideNodeContainer.GetNode(parentEntity.Transform.Children).Add(gameSidePart.Transform);
                }
            });
        }

        /// <inheritdoc />
        public override Task RemovePart([NotNull] EntityHierarchyElementViewModel parent, Entity assetSidePart)
        {
            EnsureAssetAccess();

            return InvokeAsync(() =>
            {
                Logger.Debug($"Removing entity {assetSidePart.Id} from game-side scene");
                var partId = new AbsoluteId(AssetId.Empty, assetSidePart.Id);
                var part = (Entity)FindPart(partId);
                if (part == null)
                    throw new InvalidOperationException($"The given {nameof(assetSidePart.Id)} does not correspond to any existing part.");

View on GitHub (pinned to 96fad776d2)