How to store variables to a custom .ini file?

This is an old question but I was having the same problem and happened across the solution, so I figured I’d post it for posterity.
Here’s how it works:

Your c++ class definition should look like this.

UCLASS(config=NewConfigFileName)
class YOURGAME_API AExample : public AActor
{
    GENERATED_BODY()

    UPROPERTY(Config)
          int32 test_number;
    UPROPERTY(Config)
          FString test_string;
}

Edit: Oh and I almost forgot, you can have other properties in your UPROPERTY declaration.

As you noted the UCLASS declaration will automatically create an empty .ini file for you at compile time. Open up that file and type this inside it:

[/Script/YourGame.Example]
test_number=1
test_string=hi

Note how I typed Example in the config file and not AExample. Now whatever values you assigned in the ini file will automatically be loaded into your c++ variables. However, if you want to make a change to the ini file you’ll have to completely close out and reload the editor. I haven’t yet found a way to reload values on the fly and I’m not sure there is one. You can find more info in the documentation here: Configuration Files | Unreal Engine Documentation

1 Like