UPDATE! This node comes with the Engine as standard, you don’t need to make a custom function.
You can make a blueprint exposed function in c++ to return the clean map name. I made it so I could make save files that directly relate to the current map. The built in function for map name also includes the editor type, ie “PIE-CrazyMap”, so we get the streaming level prefix and chop that from the beginning. Making sure to confirm the GEngine is valid whenever working with it.
You could easily simplify this down to 1 line without setting those variables, I just did it like this to better show what is going on.
Also, don’t forget to change the namespace to match your projects.
UFUNCTION(BlueprintPure, Category = "Tools", meta = (WorldContext = "WorldContextObject"))
static FString MapName(UObject* WorldContextObject);
FString UUEToolsBPLibrary::MapName(UObject* WorldContextObject)
FString prefix = GEngine->GetWorldFromContextObject(WorldContextObject)->StreamingLevelsPrefix;
FString name = GEngine->GetWorldFromContextObject(WorldContextObject)->GetMapName();
return "Failed to find world";