Hello,
I use a CPP script that I built to dynamically create Datatables when you select a button in editor. These usually show up so i can use them in blueprint references but after I updated to engine version 5.4 they stopped appearing in the content browser but the script/code still runs successfully?
Any ideas as to why that would of changed?
void UDataTableHelpers::CreatePrimaryDataTable(TArray<UDataTable*> UniqueTables, bool bBackupTables, FString BackupLocation)
{
//Grab the struct that is being used by this group of data tables
if (UniqueTables.Num() < 1)
{
//UE_LOG(LogTemp,Error, TEXT("Size of Unique tables is 0, cannot create from nothing!"));
return;
}
UScriptStruct* StructToUse = UniqueTables[0]->RowStruct;
if (!IsValid(StructToUse))
{
//UE_LOG(LogTemp,Error, TEXT("Table Structure is not valid for %s"), *UniqueTables[0]->GetName());
return;
}
const FString tableType = StructToUse->GetFName().ToString();
// Create a new package to store the primary data table in
FString TableName = "/Game/Data_Tables/" + tableType;
FString BackupTableName = BackupLocation + tableType;
FString SavePath = FPackageName::LongPackageNameToFilename(TableName, FPackageName::GetAssetPackageExtension());
FString BackupSavePath = BackupTableName + ".json";
UPackage* TablePackage = CreatePackage(*TableName);
//Create the the primary table that will be saved as the final
UDataTable* FinalTable = NewObject<UDataTable>(TablePackage,UDataTable::StaticClass(),*TableName,RF_Public | RF_Standalone);
FinalTable->RowStruct = StructToUse;
UE_LOG(LogTemp, Warning, TEXT("Creating Primary Data table for %s tables."), *tableType);
//iterate through the list of tables, if its the first one grab the headers if not grab the entries.
FString FinalTableString;
int32 index = 0;
for (auto& table : UniqueTables)
{
FString temp = table->GetFName().ToString();
//UE_LOG(LogTemp, Warning, TEXT("Adding %s to the primary table."), *temp);
FString CSVString = table->GetTableAsCSV();
if (index == 0)
{
FinalTableString = CSVString;
}else
{
FString splitBy = "\n";
FString header;
CSVString.Split(*splitBy, &header, &CSVString);
FinalTableString += CSVString;
}
index++;
//UE_LOG(LogTemp,Warning,TEXT("Adding: %s"), *CSVString);//This is the string from each table that need to be added to primary
}
//Put the table string together
FinalTable->CreateTableFromCSVString(FinalTableString);
TablePackage->FullyLoad();
if (TablePackage->IsDirty())
{
//UE_LOG(LogTemp,Warning,TEXT("Newly created Package for %s needs saved."), *tableType);
}
//prevent GC from wrecking table before saving
FinalTable->AddToRoot();
//Create the asset
FAssetRegistryModule::AssetCreated(FinalTable);
TablePackage->MarkPackageDirty();
// Create a backup
if (bBackupTables)
{
FString FinalTableJson = FinalTable->GetTableAsJSON();
//UE_LOG(LogTemp, Warning, TEXT("Backing up %s to %s."), *FinalTable->GetFName().ToString(), *BackupSavePath);
FFileHelper::SaveStringToFile(FinalTableJson, *BackupSavePath);
}
//Save the datatable in the package
FSavePackageArgs SaveArgs;
SaveArgs.TopLevelFlags = RF_Public | RF_Standalone;
bool bSavedTable = UPackage::SavePackage(TablePackage, FinalTable, *SavePath, SaveArgs);
//UE_LOG(LogTemp, Warning, TEXT("Package saved: %s"), bSavedTable ? TEXT("TRUE") : TEXT("FALSE"));
if (TablePackage->IsDirty())
{
//UE_LOG(LogTemp,Error,TEXT("Newly created Package for %s was not saved."), *tableType);
}
}