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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/6/9/2697d6aff5e598743dcf2565591a72a61d1e0d37.png)
What I have after duplicating to the new LevelInstance:
![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/b/9/2b9fe82b39c4ca61173dbb41570cc663935d125a.png)
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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/3/2/6323e8419c71d30048cc63ff65e030def28279f0.png)
BUT as soon as I hit Edit on the LvlInstance Actor everything snaps back to before
![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/0/1/f01e6f6b1408143b03263cedd16232f9cda43cec.png)
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: :frowning_face:](https://d1ap1mz92jnks1.cloudfront.net/images/emoji/twitter/frowning_face.png?v=12)
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.