So I’m trying to create my own Custom Game User Settings.
Cuz Unreal’s default one’s quite an spaghetti code. And I tried to simplify it, using my own structs, and Applying Settings based of Category.
I gotta ask:
Can I make my custom name for the ini of Custom Game User Settings (CndGameUserSettings.ini), and save my Settings there?
What should happen first, when it’s being initialized?
Like… Validating Settings first, then Loading Them (Applying Defaults)?
Should fetching all supported resolutions and all that be initialized when being initialized too, to determine max values?
If I set the value using this for ex.:
Does CndGameUserSettings.ini, if it doesn’t exist, gets created?
Ini files are loaded on the startup of Unreal Engine. I think they are validated on assignment.
No. If you want to have additional .ini files you have to create them yourself. (not only that but I think you need to have your categories added inside)
Here is the documentation if you need more in-depth answers.
Oh, by “create them yourself” I meant manually creating a .txt file and changing its name to .ini. (also adding your categories in square brackets and even your initial values)
I guess you can create it runtime but I don’t see why would you you want do that.
void Cnd_SetupIniFile()
{
// Set a custom name for the user settings ini file
FString Cnd_US_FilePath = FPaths::ProjectConfigDir() + TEXT("CndGameUserSettings.ini");
GGameUserSettingsIni = Cnd_US_FilePath;
// UE_LOG(LogTemp, Log, TEXT("Game User Settings will be saved in: %s"), *GGameUserSettingsIni);
bool FileExists = FPlatformFileManager::Get().GetPlatformFile().FileExists(*Cnd_US_FilePath);
if (!FileExists)
{
FString SectionName = TEXT("CndGeneral");
FString KeyName = TEXT("Version");
int32 Cnd_Version_Initial = 1;
// Write the initial version to the custom ini file
GConfig->SetInt(*SectionName, *KeyName, Cnd_Version_Initial, *Cnd_US_FilePath);
// Flush changes to disk (this creates the file)
GConfig->Flush(false, *Cnd_US_FilePath);
// UE_LOG(LogTemp, Log, TEXT("Custom ini file '%s' created with initial version %d."), *Cnd_US_FilePath, Cnd_Version_Initial);
}
}
I haven’t used FPlatformFileManager but I guess this would work. However, make sure you also set your variables because I don’t think the engine will read the newly created file on this run. (I think you’ll create it after all the .ini files are loaded)