How could I add existing levels to a World via Python? This is my most recent attempt:
loaded_level = unreal.EditorLoadingAndSavingUtils.load_map(level_path)
if loaded_level is not None:
world = unreal.EditorLevelLibrary.get_editor_world()
unreal.EditorLevelUtils.add_level_to_world(world, level_path, unreal.LevelStreamingAlwaysLoaded)
I was having issues because I was creating a World object. What I ended up doing was simply creating a new Level so for anyone reading this later, the correct steps are:
path = "/Game/..."
level_editor_subsystem = unreal.get_editor_subsystem(unreal.LevelEditorSubsystem)
level_editor_subsystem.new_level(path)
unreal_editor = unreal.get_editor_subsystem(unreal.UnrealEditorSubsystem)
world = unreal_editor.get_editor_world()
sublevel_path = "/Game/..."
unreal.EditorLevelUtils.add_level_to_world(world, sublevel_path, unreal.LevelStreamingAlwaysLoaded)
# save
level_editor.save_all_dirty_levels()