How to check ServerTravel error or check if the map exists

I am using ServerTravel for switching maps in a single player game. ServerTravel returns true even if the map does not exist. The map name will be given by the user and I have to check if it exists first. How can I do that?

You can query asset registry to check existence of map without loading it.
Something like this :

This is in case user provides only map name.
If user provides full path (“/Game/Path/To/Level”), you can put that directly in PackageNames filter and don’t need to check with a loop.

Thanks for your reply. Is there an equivalent method C++?

Of course, all blueprint methods use underlying C++ functions under the hood.

#include "AssetRegistry/IAssetRegistry.h"

if (auto AssetRegistry = IAssetRegistry::Get())
{
    TArray<FAssetData> MapList;
    AssetRegistry->GetAssetsByClass(FTopLevelAssetPath(UWorld::StaticClass()->GetPathName()), MapList);
    //...
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.