Hello all, I have a .json file with critical data to run my game, how do I include such file into the packaged game and how do I reference it from the c++ trying to access it? (file path) I know that the packaging settings have the option to add non asset directories but I’m unsure how this works (asset must be on the content folder and this is not allowed by the editor :S ).
So far this is my approach,
void UUnrealShooterDataSingleton::ParseJSON()
{
FString JsonString;
const FString fileName = "D:/Projects/UnrealProjects/UnrealShooter/Shared/UnrealShooterData.json";
FFileHelper::LoadFileToString(JsonString, *fileName);
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(JsonString);
if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
const TArray<TSharedPtr<FJsonValue>> SequencesJSON = JsonObject->GetArrayField(TEXT("sequences"));
const TArray<TSharedPtr<FJsonValue>> WavesJSON = JsonObject->GetArrayField(TEXT("waves"));
const TArray<TSharedPtr<FJsonValue>> TargetsJSON = JsonObject->GetArrayField(TEXT("targets"));
const TArray<TSharedPtr<FJsonValue>> LocationsJSON = JsonObject->GetArrayField("locations");
UUnrealShooterDataSingleton::ParseLocations(LocationsJSON);
UUnrealShooterDataSingleton::ParseTargets(TargetsJSON);
UUnrealShooterDataSingleton::ParseWaves(WavesJSON);
UUnrealShooterDataSingleton::ParseSequences(SequencesJSON);
}
}
Note that the file path is absolute and it’s saved outside the content folder, this is because the editor won’t let me add a .json file without converting it into a data table/data curve.