UE4 C++源碼 在Visual studio 2015中使用過程發現添加 try catch 以後打包通不過。追溯錯誤提示是C++的 try catch 代碼。網上查找以後發現
https://blog.csdn.net/SC32024826/article/details/78710672 html
public class XXXXXX: TargetRules
{
public XXXXX(TargetInfo Target) : base(Target)
{編輯器
……ide
Target.bForceEnableExceptions = true;函數
}網站
而後沒有報錯能生成文件。後續再觀察。using UnrealBuildTool; using System.Collections.Generic; public class MyModule : ModuleRules { public MyModule(ReadOnlyTargetRules Target) : base(Target) { // Settings go here } }
這樣的結構能夠直接使用 ui
Target.bEnableExceptions = true;
可是我使用的代碼層次是this
using UnrealBuildTool; using System.Collections.Generic; public class XXXTarget : TargetRules { public XXXTarget(TargetInfo Target) : base(Target) { Type = TargetType.Game; ExtraModuleNames.Add("szmUEDesign"); } }
並無ReadOnlyTargetRules。(搜索到這邊其實應該解決問題了,但是本身忽略重點繼續花時間搜索)spa
後面直接在源代碼搜索TargetInfo 。 發現TargetInfo 的成員變量都跟異常不相關。可是,在它的成員變量在的文件"UeBulidTarget.cs"能搜索到bEnableExceptions 。發現 bEnableExceptions出如今如下環境.net
GlobalCompileEnvironment.bEnableExceptions = Rules.bForceEnableExceptions || Rules.bBuildEditor;
此處的Rules定義以下日誌
public ReadOnlyTargetRules Rules;
追述ReadOnlyTargetRules 到TargetRulers.cs
public partial class ReadOnlyTargetRules { …… /// <summary> /// The writeable TargetRules instance /// </summary> TargetRules Inner; …… public bool bForceEnableExceptions { get { return Inner.bForceEnableExceptions; } } …… } TargetRules定義 public abstract class TargetRules { …… /// <summary> /// Enable exceptions for all modules. /// </summary> [RequiresUniqueBuildEnvironment] public bool bForceEnableExceptions = false; }
到這邊就明白調用規則了。 直接在本身的bulid文件增長如下代碼,啓用異常檢測機制。
using UnrealBuildTool; using System.Collections.Generic; public XXXTarget : TargetRules { public XXXTarget(TargetInfo Target) : base(Target) { Type = TargetType.Game; ExtraModuleNames.Add("szmUEDesign"); this.bForceEnableExceptions = true; } }
4.18(不含)以前在 bulid.cs文件添加 UEBuildConfiguration.bForceEnableExceptions = true;或者 UEBuildConfiguration.bEnableExceptions = true; 。 UE4.18以後使用 this.bForceEnableExceptions = true;解決異常
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2019-04-02問題:代碼添加 this.bForceEnableExceptions = true; UE4.19編輯器環境能夠運行,可是打包失敗。 解答:該問題是由於使用ue4官方下載生成好的環境。 當調用 this.bForceEnableExceptions 時,由於和編輯好的環境衝突,因此失敗。 解決的辦法是下載UE4官方源代碼,而後創建sln文件,本地從新生成。 而後項目引用生成後的ue4引擎。這時候打包和運行都正常了。