以Game.ini为例
其他配置的读写看这里 CoreGlobals.h,替换下面的 GGameIni 参数即可,这些字符串保存的是对应配置文件的路径。
extern CORE_API FString GEditorIni;
extern CORE_API FString GEditorPerProjectIni;
extern CORE_API FString GCompatIni;
extern CORE_API FString GLightmassIni;
extern CORE_API FString GScalabilityIni;
extern CORE_API FString GHardwareIni;
extern CORE_API FString GInputIni;
extern CORE_API FString GGameIni;
extern CORE_API FString GGameUserSettingsIni;
写入
会写入到YourGame\Saved\Config\Windows\Game.ini 中
void AMyActor::WriteIniFile()
{
if (!GConfig) return;
//String
GConfig->SetString(
*VictorySection,
TEXT("Str"),
TEXT("HelloWorld"),
GGameIni
);
//FColor
GConfig->SetColor(
*VictorySection,
TEXT("Red"),
FColor(255, 0, 0, 255),
GGameIni
);
//FVector
GConfig->SetVector(
*VictorySection,
TEXT("Location"),
FVector(0, 0, 0),
GGameIni
);
//FRotator
GConfig->SetRotator(
*VictorySection,
TEXT("Rotation"),
FRotator(90, 0, 0),
GGameIni
);
GConfig->Flush(false, GGameIni);
}
读取
void AMyActor::ReadIniFile()
{
FString Str;
GConfig->GetString(
*VictorySection,
TEXT("Str"),
Str,
GGameIni
);
GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Blue, Str);
FColor Color;
GConfig->GetColor(
*VictorySection,
TEXT("Red"),
Color,
GGameIni
);
GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Blue, Color.ToString());
FVector Vector;
GConfig->GetVector(
*VictorySection,
TEXT("Location"),
Vector,
GGameIni
);
GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Blue, Vector.ToString());
FRotator Rotator;
GConfig->GetRotator(
*VictorySection,
TEXT("Rotation"),
Rotator,
GGameIni
);
GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Blue, Rotator.ToString());
}