I like load and the read/write a custom ini file, i have created in my “Config” folder a file called “DefaultGameSettings.ini” with this content:
[Profile]
pAccountName=Hello
and a object class with:
GameSettingsConfig.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "Object.h"
#include "GameSettingsConfig.generated.h"
/**
*
*/
UCLASS( Config = GameSettings )
class GAMENAME_API UGameSettingsConfig : public UObject
{
GENERATED_BODY()
UPROPERTY( Config )
FString pAccountName;
};
GameSettingsConfig.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "GAMENAME.h"
#include "GameSettingsConfig.h"
with this i get at load the editor the generation of the ini files in the Saved folder but are empty with 2 space lines only in the sub Windows folder.
Then to read & write the value i using the Rama’s plugin (39) Rama's Extra Blueprint Nodes for You as a Plugin, No C++ Required! - Blueprint - Unreal Engine Forums! with some changes, adding support to read & write data from the custom ini file:
VictoryBPFunctionLibrary.h
/** Get Custom Config Var! These are stored in Saved/Config/Windows/GameSettings.ini */
UFUNCTION(BlueprintPure, Category = "VictoryBPLibrary|Config Reader")
static FString ConfigGetCustomConfigVar_String(FString SectionName, FString VariableName);
/** Set Custom Config Var! These are stored in Saved/Config/Windows/GameSettings.ini */
UFUNCTION(BlueprintCallable, Category = "VictoryBPLibrary|Config Writer")
static void ConfigSetCustomConfigVar_String(FString SectionName, FString VariableName, FString Value);
VictoryBPFunctionLibrary.cpp
FString UVictoryBPFunctionLibrary::ConfigGetCustomConfigVar_String(FString SectionName,FString VariableName)
{
if(!GConfig) return "";
//~~~~~~~~~~~
FString Value;
GConfig->GetString(
*SectionName,
*VariableName,
Value,
FString( TEXT( "GameSettings" ) )
);
return Value;
}
void UVictoryBPFunctionLibrary::ConfigSetCustomConfigVar_String(FString SectionName,FString VariableName, FString Value)
{
if(!GConfig) return;
//~~~~~~~~~~~
GConfig->SetString(
*SectionName,
*VariableName,
*Value,
FString( TEXT( "GameSettings" ) )
);
GConfig->Flush( false, FString( TEXT( "GameSettings" ) ) );
}
Then in the Level Blueprint i place this two nodes, the get attached to one event tick and to print to print in the screen the value and the set to the Begin place node with the info of “Profile” & “pAccountName” and “HelloWorld”.
Problems:
1º- When i get the value give me “” = null, but if i set the value to for example “HelloWorld” at get i get the “HelloWorld” and if i restart the editor/engine and only get the value i get the “HelloWorld” WHERE IS STORED that value because don’t is in my .ini and don’t is in any file of my Saved folder or in Config/ or in the engine folder, then WHERE IS?
2º- How make to work well with my custom ini file, because is created in saved but is empty and my value don’t store in my custom .ini.