How can i reference actors in a LevelInstance?

I started with this in a BP but went over to Python for convenience, but I think it can be achieved in both.
What I do:

What I am stuck with now is, that I want to attach some of the actors in the LevelInstance to another.
But how can get references to these new actors in the level instance?

To give some context:
I create a Level asset in Blueprint

And the last node ActorsToLevel is this function:

import unreal
import os

def MoveActorsToLevelInstance(actors, world):
    #getting Editor Actor Subsystem 
    EditorActorSubsystem = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
    
    #parent BPShelfBuilder transform. This is always added first in the array.
    parentTransform = actors[0].get_actor_transform()

    #resetting transform because LevelInstance will be transformed
    actors[0].set_actor_transform(unreal.Transform(location=[0, 0, 0]), sweep=False, teleport=False)

    EditorActorSubsystem.duplicate_actors(actors, world)
    EditorActorSubsystem.destroy_actors(actors)
    unreal.EditorAssetLibrary.save_loaded_asset(world)

    #spawning new actor
    newInstanceActor = unreal.EditorLevelLibrary.spawn_actor_from_object(world, parentTransform.translation, parentTransform.rotation.rotator())

    return newInstanceActor

(mainly from here Improving the MegaAssemblies Workflow | Blog)

What i have as actors before:
image

What I have after duplicating to the new LevelInstance:
image

What I want to do now is reattach the actors to another in the LevelInstance.
But I have no idea how to reference them in there…

I got the attachment to work in principal. By using the LevelInstance as World Context Object for all Get Actors nodes.

That way I get everything attached again.
image

BUT as soon as I hit Edit on the LvlInstance Actor everything snaps back to before
image

And the function gives me this error:
LogEditorAssetSubsystem: Error: SaveLoadedAsset failed: Asset is not registered. The object 'A01_0FB02BCA46B1EE44695A76BA664F5DBE' is not an asset.

When I check the path of that level, it is in /Temp/Game/Maps, so it is just a copy of the original level.

How do i save my changes to the actual level referenced by the levelInstance?

I talked to some devs at Unreal Fest Prague and they told me to fix it in code not in Blueprint…
That’s what I did. Would have loved to find a BP solution. :frowning_face:

One thing to notice, that you need to do your operations right after duplicating the actors before you save the level!
Otherwise you run in the same problems I had in BPs.