ue4-读写配置文件
读写 .ini 配置文件,(暂时只测了Windows)
- 这里已 Game.ini 为例,
- 其他配置的读写看这里 CoreGlobals.h,替换下面的 GGameIni 参数即可,这些字符串保存的是对应配置文件的路径
1
2
3
4
5
6
7
8
9
10extern 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;
1. 读取
会先从 YourGame\Config\DefaultGame.ini 中读取,读不到会再从 YourGame\Saved\Config\Windows\Game.ini 中读取
1
2
3
4
5
6
7float ValueReceived =0.f;
GConfig->GetFloat(
TEXT("/Script/MyTest.MyTestCharacter"),
TEXT("FixedCameraDistance"),
ValueReceived,
GGameIni
);
2. 写入
写的数据会写到 YourGame\Saved\Config\Windows\Game.ini 中
1
2
3
4
5
6
7
8
9const FString WriteSection = "MyCustomSection";
//String
GConfig->SetString(
*WriteSection,
TEXT("key1"),
TEXT("Hello world"),
GGameIni
);
GConfig->Flush(false, GGameIni);