UE5 移植Editor或Developer模块到Runtime(以运行时弹窗为例)
要将源码中的非运行时模块移植到Runtime下使用,使用了前面的方法后测试发现还是不能在打包后使用,可能是个人水平有限,需要继续努力,于是又尝试了另一种方法,打包后测试成功,这里记录方法,希望能帮助到有相同需求的人。
参照源码中的模块名自己新建一个模块
新建模块后项目中的...uproject、
{"FileVersion": 3,"EngineAssociation": "{EBFA7FA1-4EAF-5418-B79F-C5B3AA441776}","Category": "","Description": "","Modules": [{"Name": "ACustomOpenWindow","Type": "Runtime","LoadingPhase": "Default","AdditionalDependencies": ["Engine"]},{"Name": "RTDesktopPlatform","Type": "Runtime","LoadingPhase": "Default"}]
}
...WindowEditor.Target.cs、
// Copyright Epic Games, Inc. All Rights Reserved.using UnrealBuildTool;
using System.Collections.Generic;public class ACustomOpenWindowEditorTarget : TargetRules
{public ACustomOpenWindowEditorTarget( TargetInfo Target) : base(Target){Type = TargetType.Editor;DefaultBuildSettings = BuildSettingsVersion.V5;IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_4;ExtraModuleNames.Add("ACustomOpenWindow");RegisterModulesCreatedByRider();}private void RegisterModulesCreatedByRider(){ExtraModuleNames.AddRange(new string[] { "RTDesktopPlatform" });}
}
...Window.Target.cs内中的变化
// Copyright Epic Games, Inc. All Rights Reserved.using UnrealBuildTool;
using System.Collections.Generic;public class ACustomOpenWindowTarget : TargetRules
{public ACustomOpenWindowTarget(TargetInfo Target) : base(Target){Type = TargetType.Game;DefaultBuildSettings = BuildSettingsVersion.V5;IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_4;ExtraModuleNames.Add("ACustomOpenWindow");RegisterModulesCreatedByRider();}private void RegisterModulesCreatedByRider(){ExtraModuleNames.AddRange(new string[] { "RTDesktopPlatform" });}
}
自己创建的模块名是RTDesktopPlatform.h、RTDesktopPlatform.cpp,将模块名修改为RTDesktopPlatformModule.h、RTDesktopPlatformModule.cpp,(但是发现类名修改与类内的FRTDesktopPlatformModule名没啥关系,RTDesktopPlatform上加不加Module,在类内都一样)
RTDesktopPlatform.Build.cs中的修改,PrivateIncludePaths.Add("RTDesktopPlatform/Private");的目的是让模块的头文件只限制在当前模块内