Hey guys I’ve been using UE4 C++ for the past 6 months and I still don’t know exactly how to do this. I am trying to create config variables for user gameplay preferences and graphics settings that would be stored on a custom .ini file.
This is what I have now,
This complies with no problems and it generates an .ini file called UserSettings, but the file is blank. Am I on the right track? Can someone maybe show me how to do this correctly?
I’ve read that many times but it doesn’t show how to write to a custom ini file. I want my variables to be in a separate ini file not with the defaultgame.ini.
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:
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
consider that I have my project cooked with some default settings, but on a specific machine I want to change them.
How can I override the values in .ini that has been packaged?
For writing to custom ini file, instead of using one of the globals as file name (GGameIni etc), you need to pass in your file’s absolute path. For instance, if I want to save data in an ini called DefaultMyGame.ini stored in [Project]/Config, I’ll use as path FPaths::ProjectConfigDir() / TEXT("DefaultMyGame.ini").
And for the section, it’s as others said: /Script/YourProjectName.ClassName
If it is a plugin, it’ll be /Script/ModuleName.ClassName