Blueprint doesn't affect dynamically attached actor in editor preview, works in standalone game

I have a blueprint which shows or hides an actor when the player presses the tab key and enlarges it when they press the left shift key (similar to a map overlay in an RPG, for example). The actor itself starts off empty, but when play starts I attach a child actor with some geometry to it dynamically. The geometry is received over the network from a custom server, so I can’t simply create it ahead of time in the editor.

The blueprint

works correctly when I launch the level as a standalone game, but when I launch it as a preview in the editor the keypresses have no effect on the dynamically added actor (although if I add an actor statically, e.g. a cube, then it does get modified as I’d expect).

I’m attaching the dynamic actor using C++, by calling

childActor->AttachToActor(parentActor, FAttachmentTransformRules::KeepRelativeTransform);

Any idea what I might be doing wrong? Could the childActor be getting attached to some component other than DefaultSceneRoot1 when I’m running in the editor preview? And why would this be different between the editor preview and the standalone game?

Thanks in advance!

Answering my own question:

When you run a preview-in-editor, you get two copies of each actor, the “true” one (i.e. the one being edited) and a temporary one which I think the editor creates so that you’re not interfering with the true actor during the preview.

The true actor has the name you would expect; the temporary one is prefixed with UEDPIE_0_ (where the 0 is actually an integer counter, but I’m not sure what it counts).

I was using FindObject(ANY_PACKAGE, TEXT("Placeholder")) to locate the placeholder object. It turns out that this matches against the unqualified name of the object. In the preview-in-editor case, because of the temporary copy of the actor, there are two objects that have the same unqualified name even though their fully qualified names are different - and it was simply finding the wrong one of them.

So the fix was to check whether we’re running as a preview-in-editor and use the correct fully-qualified name - "/Game/UEDPIE_0_MyScene.MyScene:PersistentLevel.Placeholder" - in this case. UWorld has a method, IsPlayInEditor() for doing the check.