You don’t need the asset registry and loading part . Also you are passing wrong param at first param of OpenLevel Func. WorldContextObject is an object that engine can access the current World from it . Try UGameplayStatics::OpenLevel(GetWorld(), FName("ThirdPersonMap"))
If you are calling this from a UObject.
Thank you @irajsb. You were absolutely right about GetWord().
Loading maps in editor now works.
But at cooked runtime loading another level still doesn’t work.
Test setup:
Game have two maps: ThirdPersonMap and TestMap
Game starts with ThirdPersonMap
A button press event calls the below function: LoadLevel(TestMap)
Results:
In editor: works
During runtime: don’t work
In both cases, however, the registry finds the TestMap asset!
And both methods ( GetAsset(), LoadObject() ) works in Editor and both don’t work at runtime.
.
(BTW, i am doing the registry part because i am working on a modding framework.
But in this test case I’m only loading assets that are already included in the main game.
Should be easy, right? Obviously not. )
Works fine here I only slightly changed the code because you’re not supposed to explicitly load Level assets so maybe that was the issue, not sure, I didn’t test original code
AssetRegistry.GetAssetsByClass(FTopLevelAssetPath("/Script/Engine.World"), AssetData);
for (auto& Item : AssetData)
{
if (*Item.AssetName.ToString() == FName(*PakContentPath))
{
return TSoftObjectPtr<UWorld>(Item.GetObjectPathString());
}
}
I found the explanation for my empty levels problem.
The Pak file i mounted did not contain the standard editor shape actors, i used for quick testing.
However, if a mod level consists only of self-created blueprint actors, loading works fine.
Summary:
mount mod pak
set virtual path [Game] to mod pak
load mod level
set virtual path [Game] to main game pak
Due to this order, all main game assets are invisible to a user-created mod level.
But the main game could offer a plugin (GameShared) to make assets available to modders.