添加module的流程
右键.uproject文件 添加新的模块
{
“FileVersion”: 3,
“EngineAssociation”: “4.16”,
“Category”: “”,
“Description”: “”,
“Modules”: [
{
“Name”: “UE4Cook”,
“Type”: “Runtime”,
“LoadingPhase”: “Default”,
“AdditionalDependencies”: [
“Engine”,
“CoreUObject”
]
},
{
“Name”: “UE4CookTestEditor”, //新模块名称
“Type”: “Editor”, //运行模式 Runtime 表示 既在editor模式下运行 又在发布版运行
“LoadingPhase”: “PostEngineInit”, //模块加载时机
“AdditionalDependencies”: [
“Engine”,
“CoreUObject”
]
}
]
}
添加配置文件
在Source下 参照原有的文件接口 添加UE4CookTestEditor 文件夹 里面相应创建xx.h xx.build.cs xx.cpp文件
.build.cs
using UnrealBuildTool;
public class UE4CookTestEditor : ModuleRules
{
public UE4CookTestEditor(ReadOnlyTargetRules Target) : base(Target)
{
PublicDependencyModuleNames.AddRange(new string[] {“Core”, “CoreUObject”, “Engine”, “InputCore”, “RHI”,”RenderCore”, “ShaderCore” });
PublicDependencyModuleNames.Add(“UE4Cook”);
//主模块
PrivateDependencyModuleNames.AddRange(new string[] {“UnrealEd” });
}
}
其中。h文件
#pragma once
include “CoreMinimal.h” include “Engine.h” include “ModuleManager.h” include “UnrealEd.h” //为了使用Editor相关的函数 可以不加 class FUE4CookTestEditorModule: public IModuleInterface
{
};
.cpp文件
include “UE4CookTestEditor.h” include “Modules/ModuleManager.h” IMPLEMENT_PRIMARY_GAME_MODULE( FUE4CookTestEditorModule, UE4CookTestEditor); //此处的名称要与。uproject中配置的名称保持一致
添加完以上文件后 右键。uproject 重新生成vsstudio文件
编辑UE4CookTestEditor.Target.cs
using UnrealBuildTool;
using System.Collections.Generic;
public class UE4CookEditorTarget : TargetRules
{
public UE4CookEditorTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Editor;
ExtraModuleNames.AddRange( new string[] { "UE4CookTestEditor" } );
}
}
编译程序并运行 点开/developTools/Modules 查看自定义的module是否正确添加
【UE4 添加自定义的module】相关工程地址
http://download.csdn.net/download/maxiaosheng521/10221636
主要要点 一定要确保模块名称在文件名 。build.cs .h 。cpp中的一致性 模块创建失败多是由于名称不一致引起的