target.cs 中检测是否是源码版引擎

可以从 TargetRules 中使用 bIsEngineInstalled 来检查。

它调用的是 UnrealBuildTool.IsEngineInstalled(),检测的也是Engine/Build/InstalledBuild.txt 文件是否存在。

1
2
3
4
5
6
7
8
/// <summary>
/// Expose a setting for whether or not the engine is installed
/// </summary>
/// <returns>Flag for whether the engine is installed</returns>
public bool bIsEngineInstalled
{
get { return UnrealBuildTool.IsEngineInstalled(); }
}

在 UE4 与 5 中还有些区别,在 UE4 中调用的是 UnrealBuildTool.IsEngineInstalled(),定义在UnrealBuildTool.cs
在 UE5 中,调用的是 Unreal.IsEngineInstalled() 定义在Unreal.cs

UnrealBuildTool.cs or Unreal.cs(UE5)
1
2
3
4
5
6
7
8
9
10
11
12
/// <summary>
/// Returns true if UnrealBuildTool is running using installed Engine components
/// </summary>
/// <returns>True if running using installed Engine components</returns>
static public bool IsEngineInstalled()
{
if (!bIsEngineInstalled.HasValue)
{
bIsEngineInstalled = FileReference.Exists(FileReference.Combine(EngineDirectory, "Build", "InstalledBuild.txt"));
}
return bIsEngineInstalled.Value;
}