Hello everyone,
I am trying to save some data about a map when it is saved. This data should be accessible from an actor if he has the name of a level. What I tried was a custom Editor Module that creates a usasset file whenever the map is saved, like this:
void FCustomEditorModule::StartupModule()
{
FEditorDelegates::PreSaveWorld.AddRaw(this, &FCustomEditorModule::OnMapSaved);
}
void FCustomEditorModule::OnMapSaved(uint32 SaveFlags, UWorld* World)
{
FString FileName;
FPaths::GetPath(World->GetPathName()).Split("Game/", NULL, &FileName);
FileName = FPaths::Combine(FPaths::GameContentDir(), FileName, World->GetName() + "_meta.uasset");
UPackage* DataPackage = CreatePackage(NULL, TEXT("/Test/MetaPackage"));
UdtLevelData* LevelData = NewObject<UdtLevelData>(DataPackage);
LevelData->SomeVar = 10;
FAssetRegistryModule::AssetCreated(LevelData);
UPackage::SavePackage(DataPackage, LevelData, RF_Standalone, *FileName);
}
The uasset gets created but it does not appear in the content browser. Also, I don’t know how an actor would be able to read this data in-game. Then another issue is how to handle name changes/moving of maps. Any ideas?