Hi so I was wondering is there any way to simplify this code because I’m planning on adding more if / else if statements and I feel like it’s going to look quite messy. Maybe templates for the function could fix this, but I’m not sure if that would even work, any help is much appreciated, thank you
void ATestingGameMode::SetNewGameState(const FString& GameStateName)
{
FActorSpawnParameters SpawnInfo;
SpawnInfo.Instigator = Instigator;
SpawnInfo.ObjectFlags |= RF_Transient;
if (GameStateName == "TestGameState")
{
ATestGameState* TestGameState = GetWorld()->SpawnActor<ATestGameState>(SpawnInfo);
GameState = TestGameState;
}
else if (GameStateName == "InGameState")
{
AInGameState* TestGameState = GetWorld()->SpawnActor<AInGameState>(SpawnInfo);
GameState = TestGameState;
}
}