Long story, I need to change the default value of the variables of a C++ class without recompiling the code.
The approach I took was to use config file.
Following the documentation I wrote the following code in a file called SimonSaysGameMode.h in Root/Source/
UCLASS(BlueprintType, Config=Game)
class APPTREATMENTDEMO_API ASimonSaysGameMode : public AGameModeBase
{
GENERATED_BODY()
public:
ASimonSaysGameMode();
UPROPERTY(Config)
int RoundsToRaiseDifficulty;
UPROPERTY(Config)
int FaultPenaltyPoints;
...
};
I added the followind code in the file in Root/Config/DefaultEngine.ini
[/Script/SimonSaysGameMode.SimonSaysGameMode]
RoundsToRaiseDifficulty=10
FaultPenaltyPoints=1
How can I make the engine set the default values of this class based on the .ini file?
P.S: I made some code for explicit initialization, but, as far as I know, UE4 should be able to do this automatically.
ASimonSaysGameMode::ASimonSaysGameMode()
{
PrimaryActorTick.bCanEverTick = true;
GConfig->GetInt(
TEXT("/Script/SimonSaysGameMode.SimonSaysGameMode"),
TEXT("RoundsToRaiseDifficulty"),
RoundsToRaiseDifficulty,
GEngineIni
);
GConfig->GetInt(
TEXT("/Script/SimonSaysGameMode.SimonSaysGameMode"),
TEXT("FaultPenaltyPoints"),
FaultPenaltyPoints,
GEngineIni
);
}