unreal对于配置文件的读取

一、unreal文档中说明的层级关系

其实unreal文档对该内容有说明
File Hierarchy
The configuration file hierarchy is read in starting with Base.ini, with values in later files in the hierarchy overriding earlier values. All files in the Engine folder will be applied to all projects, while project-specific settings should be in files in the project directory. Finally, all project-specific and platform-specific differences are saved out to [ProjectDirectory]/Saved/Config/[Platform]/[Category].ini
The below file hierarchy example is for the Engine category of configuration files.
Engine/Config/Base.ini Base.ini is usually empty.
Engine/Config/BaseEngine.ini
Engine/Config/[Platform]/base[Platform]Engine.ini
[ProjectDirectory]/Config/DefaultEngine.ini
Engine/Config/[Platform]/[Platform]Engine.ini
[ProjectDirectory]/Config/[Platform]/[Platform]Engine.ini

二、约定的文件夹名称

EngineSourceRuntimeCorePrivateMiscPaths.cpp
FString FPaths::EngineDir()
{
return FString(FPlatformMisc::EngineDir());
}
……
FString FPaths::EngineConfigDir()
{
return FPaths::EngineDir() + TEXT("Config/");
}
……
FString FPaths::RootDir()
{
return FString(FPlatformMisc::RootDir());
}

FString FPaths::ProjectDir()
{
return FString(FPlatformMisc::ProjectDir());
}
……
FString FPaths::EnginePlatformExtensionsDir()
{
return FPaths::EngineDir() + TEXT("Platforms/");
}

FString FPaths::ProjectPlatformExtensionsDir()
{
return FPaths::ProjectDir() + TEXT("Platforms/");
}

1、引擎文件夹的由来

EngineSourceRuntimeCorePrivateGenericPlatformGenericPlatformMisc.cpp
const TCHAR* FGenericPlatformMisc::EngineDir()
{
FString& EngineDirectory = TLazySingleton<FStaticData>::Get().EngineDirectory;
if (EngineDirectory.Len() == 0)
{
// See if we are a root-level project
FString DefaultEngineDir = TEXT("../../../Engine/");
……
}
由于引擎的可执行文件通常位于"……EngineBinariesWin64UE4Editor.exe" 文件夹下,所以这个路径找到的也是对的。

2、project文件的路径

这个用脚指头想想应该就可以想到,在打开一个项目的时候是需要指定项目的文件夹的,所以这个project文件夹的获得并没有什么问题。

三、配置的层级

EngineSourceRuntimeCorePrivateMiscConfigCacheIni.cpp
/**
* Structure to define all the layers of the config system. Layers can be expanded by expansion files (NoRedist, etc), or by ini platform parents
* (coming soon from another branch)
*/
struct FConfigLayer
{
// Used by the editor to display in the ini-editor
const TCHAR* EditorName;
// Path to the ini file (with variables)
const TCHAR* Path;
// Path to the platform extension version
const TCHAR* PlatformExtensionPath;
// Special flag
EConfigLayerFlags Flag;

} GConfigLayers[] =
{
/**************************************************
**** CRITICAL NOTES
**** If you change this array, you need to also change EnumerateConfigFileLocations() in ConfigHierarchy.cs!!!
**** And maybe UObject::GetDefaultConfigFilename(), UObject::GetGlobalUserConfigFilename()
**************************************************/

// Engine/Base.ini
{ TEXT("AbsoluteBase"), TEXT("{ENGINE}Base.ini"), TEXT(""), EConfigLayerFlags::Required },

// Engine/Base*.ini
{ TEXT("Base"), TEXT("{ENGINE}{ED}{EF}Base{TYPE}.ini") },
// Engine/Platform/BasePlatform*.ini
{ TEXT("BasePlatform"), TEXT("{ENGINE}{ED}{PLATFORM}/{EF}Base{PLATFORM}{TYPE}.ini"), TEXT("{EXTENGINE}/{ED}{EF}Base{PLATFORM}{TYPE}.ini"), },
// Project/Default*.ini
{ TEXT("ProjectDefault"), TEXT("{PROJECT}{ED}{EF}Default{TYPE}.ini"), TEXT(""), EConfigLayerFlags::AllowCommandLineOverride | EConfigLayerFlags::GenerateCacheKey },
// Engine/Platform/Platform*.ini
{ TEXT("EnginePlatform"), TEXT("{ENGINE}{ED}{PLATFORM}/{EF}{PLATFORM}{TYPE}.ini"), TEXT("{EXTENGINE}/{ED}{EF}{PLATFORM}{TYPE}.ini") },
// Project/Platform/Platform*.ini
{ TEXT("ProjectPlatform"), TEXT("{PROJECT}{ED}{PLATFORM}/{EF}{PLATFORM}{TYPE}.ini"), TEXT("{EXTPROJECT}/{ED}{EF}{PLATFORM}{TYPE}.ini") },

// UserSettings/.../User*.ini
{ TEXT("UserSettingsDir"), TEXT("{USERSETTINGS}Unreal Engine/Engine/Config/User{TYPE}.ini") },
// UserDir/.../User*.ini
{ TEXT("UserDir"), TEXT("{USER}Unreal Engine/Engine/Config/User{TYPE}.ini") },
// Project/User*.ini
{ TEXT("GameDirUser"), TEXT("{PROJECT}User{TYPE}.ini"), TEXT(""), EConfigLayerFlags::GenerateCacheKey },
};

从代码中看,这里的ED和EF分别表示Expand Director和Expand File
static FString GetExpansionPath(const FConfigLayerExpansion& Expansion, const FString& LayerPath, bool bHasPlatformTag)
{
// replace the expansion tags
FString ExpansionPath = LayerPath.Replace(TEXT("{ED}"), Expansion.DirectoryPrefix, ESearchCase::CaseSensitive);
ExpansionPath = ExpansionPath.Replace(TEXT("{EF}"), Expansion.FilePrefix, ESearchCase::CaseSensitive);
……
}

/**
* This describes extra files per layer, most so that Epic needs to be able to ship a project, but still share the project
* with licensees. These settings are the settings that should not be shared outside of Epic because they could cause
* problems if a licensee blindly copy and pasted the settings (they can't copy what they don't have!)
*/
struct FConfigLayerExpansion
{
// The subdirectory for this expansion (ie "NoRedist")
const TCHAR* DirectoryPrefix;
// The filename prefix for this expansion (ie "Shippable")
const TCHAR* FilePrefix;
// Optional flags
EConfigLayerFlags Flag;
} GConfigLayerExpansions[] =
{
/**************************************************
**** CRITICAL NOTES
**** If you change this array, you need to also change EnumerateConfigFileLocations() in ConfigHierarchy.cs!!!
**************************************************/

// The base expansion (ie, no expansion)
{ TEXT(""), TEXT("") },

// When running a dedicated server - does not support {PLATFORM} layers, so those are skipped
{ TEXT(""), TEXT("DedicatedServer"), EConfigLayerFlags::DedicatedServerOnly },
// This file is remapped in UAT from inside NFL or NoRedist, because those directories are stripped while packaging
{ TEXT(""), TEXT("Shippable") },
// Hidden directory from licensees
{ TEXT("NotForLicensees/"), TEXT("") },
// Settings that need to be hidden from licensees, but are needed for shipping
{ TEXT("NotForLicensees/"), TEXT("Shippable") },
// Hidden directory from non-Epic
{ TEXT("NoRedist/"), TEXT("") },
// Settings that need to be hidden from non-Epic, but are needed for shipping
{ TEXT("NoRedist/"), TEXT("Shippable") },
};

四、文件的举例

UnrealEngine-releaseEngineConfigBaseEngine.ini
UnrealEngine-releaseEngineConfigWindowsBaseWindowsEngine.ini
UnrealEngine-releaseEngineConfigWindowsWindowsEngine.ini
ProjectProjectConfigDefaultEngine.ini
但是通常并没有配置platform和user特有的配置,所以这个就不举例子了。

五、一个比较正式的文档说明

一些变量替换说明
Valid tokens are as follows:
{PROJECT}
The project directory
Has no permutations
Token ends in a ‘/’
{ENGINE}
The engine directory
Has no permutations
Token ends in a ‘/’
{TYPE}
The type of ini file it is
Expands for each ini type; Game, Input, Engine, Editor, etc
{ED}
The DirectoryPrefixs defined in GConfigLayerExpansions
NotForLicensees, NoRedist, etc
Expands for each DirectoryPrefix in GConfigLayerExpansions
Token ends in a ‘/’
{EF}
The FilePrefixs defined in GConfigLayerExpansions
DedicatedServer, etc
Expands for each FilePrefix specified in GConfigLayerExpansions
{PLATFORM}
The current platform and any parent platform(s) in the IniParentChain
Expands once for each platform in the chain

六、为什么看这个配置

其实是为了看在编译蓝图的时候查看下对应的虚拟机指令,这个展示时需要配置
Kismet节的CompileDisplaysTextBackend和CompileDisplaysBinaryBackend两个配置项的bool值决定的,所以要配置这个两个文件夹还是需要在这些文件中进行配置的。

原文地址:https://www.cnblogs.com/tsecer/p/14310205.html