I always try to code in a way that is designer friendly, even if I’m working on my own. It seems you would be better served by using a DataTable. You can create and edit these in editor or export/import data to .csv and .json.
DataTables are built from a struct, make sure your struct is properly exposed to the editor.
Everything you need to know about referencing a DataTable in C++ and accessing its rows can be found in these links:
You dont actually need Excel to work with data tables anymore, those links are a little old. In the content browser RightClick->Miscellaneous->DataTable to create a new table. A popup asks you for a struct to base the table on, just give it your FWaveData struct and you can start adding rows for each wave.
Here’s an example of how I would approach it. I havn’t compiled any of this, just copy/pasted from a few sources and tweaked, but it should give you an idea of how to set it up.
In .h
USTRUCT(BlueprintType)
struct FWaveData
{
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 MaxSpawnsPerWave;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 MaxSpawnsAtATime;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<int32> SpawnPriorities;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<TSubclassOf<AEnemy_Base>> EnemyTypes;
};
UPROPERTY(BlueprintReadOnly)
UDataTable* WaveDataTable;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FWaveData CurrentWaveData;
In .cpp
AZombieSpawnTutorial::AZombieSpawnTutorial() //Find the editor asset in the constructor
{
ConstructorHelpers::FObjectFinder<UDataTable> WaveDataTable_BP(TEXT("DataTable'/Game/DataTables/ExcelExample.ExcelExample'"));
WaveDataTable= WaveDataTable_BP.Object;
}
AZombieSpawnTutorial::IterateWave()
{
CurrentWave++;
FString WaveName = FString::FromInt(CurrentWave);
CurrentWaveData = WaveDataTable->FindRow<FWaveData>(FText::FromString(WaveName));
OnBeginSpawnWave();
}
The resulting DataTable in editor. Super easy to edit!