概要
UnrealEngine のモジュール追加についてのメモ書きです。
エディタ用モジュールの追加手順を記録しています。
環境
Windows10
Visual Studio 2017
UnrealEngine 4.22
参考
以下を参考にさせて頂きました、ありがとうございます。
モジュールについて
【UE4】モジュール追加
https://qiita.com/kanurapoison/items/e4b551a1f22b85162c70
https://qiita.com/go_astrayer/items/5d001a9cde182488f9f3
モジュール追加手順
ファイル追加と設定ファイルの書き換えが必要です。
モジュールソースの作成
モジュール名を決めてフォルダを作成、それをプロジェクトの[Source]フォルダ以下へ配置する。フォルダには[***.Build.cs][.h][.cpp]のファイルを置く。
以下[TestModuleEd]というモジュールを作成する場合は以下のようになります。
namespaceUnrealBuildTool.Rules{publicclassTestModuleEd:ModuleRules{publicTestModuleEd(ReadOnlyTargetRulesTarget):base(Target){PublicIncludePaths.AddRange(newstring[]{"TestModuleEd",// ... add public include paths required here ... });PrivateIncludePaths.AddRange(newstring[]{"TestModuleEd",// ... add other private include paths required here ... });PublicDependencyModuleNames.AddRange(newstring[]{"Core","CoreUObject","Engine",// ... add other public dependencies that you statically link with here ... });PrivateDependencyModuleNames.AddRange(newstring[]{// ... add private dependencies that you statically link with here ... });DynamicallyLoadedModuleNames.AddRange(newstring[]{// ... add any modules that your module loads dynamically here ... });}}}#pragma once
#include "CoreMinimal.h"
#include "Modules/ModuleInterface.h"
#include "Modules/ModuleManager.h"
/**
* The public interface to this module
*/classITestModuleEd:publicIModuleInterface{public:/**
* Singleton-like access to this module's interface. This is just for convenience
* Beware of calling this during the shutdown phase, though. Your module might have been unloaded already.
*
* @return Returns singleton instance, loading the module on demand if needed
*/staticinlineITestModuleEd&Get(){returnFModuleManager::LoadModuleChecked<ITestModuleEd>("TestModuleEd");}/**
* Checks to see if this module is loaded and ready. It is only valid to call Get() if IsAvailable() returns true.
*
* @return True if the module is loaded and ready to use
*/staticinlineboolIsAvailable(){returnFModuleManager::Get().IsModuleLoaded("TestModuleEd");}};#include "TestModuleEd/TestModuleEd.h"
classFTestModuleEd:publicITestModuleEd{/** IModuleInterface implementation */virtualvoidStartupModule()override;virtualvoidShutdownModule()override;};IMPLEMENT_MODULE(FTestModuleEd,TestModuleEd)voidFTestModuleEd::StartupModule(){// This code will execute after your module is loaded into memory (but after global variables are initialized, of course.) }voidFTestModuleEd::ShutdownModule(){// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, // we call this function before unloading the module. }ファイル内容の修正
追加したモジュールの情報を反映させるために設定ファイルに追記します。
修正するファイルはエディタ用モジュールを想定し、[MyProject.uproject][MyProject.Build.cs][MyProjectEditor.Target.cs]の3ファイルです。
Modulesに追加します。
{
"FileVersion": 3,
"EngineAssociation": "4.22",
"Category": "",
"Description": "",
"Modules": [
{
"Name": "MyProject",
"Type": "Runtime",
"LoadingPhase": "Default",
"AdditionalDependencies": [
"Engine"
]
}
## ここから追加↓、(カンマに注意)
,{
"Name": "TestModuleEd",
"Type": "Editor",
"LoadingPhase": "PostEngineInit"
}
## ここまで↑
],
"Plugins": [
{
"Name": "EditorTests",
"Enabled": true
},
]
}
PublicDependencyModuleNamesに追加します。
usingUnrealBuildTool;publicclassMyProject:ModuleRules{publicMyProject(ReadOnlyTargetRulesTarget):base(Target){PCHUsage=PCHUsageMode.UseExplicitOrSharedPCHs;PublicDependencyModuleNames.AddRange(newstring[]{"Core","CoreUObject","Engine","InputCore"});PublicDependencyModuleNames.AddRange(newstring[]{"TestModuleEd"});// ←ここを追加PrivateDependencyModuleNames.AddRange(newstring[]{"Slate","SlateCore",});}}ExtraModuleNameに追加します。
usingUnrealBuildTool;usingSystem.Collections.Generic;publicclassMyProjectEditorTarget:TargetRules{publicMyProjectEditorTarget(TargetInfoTarget):base(Target){Type=TargetType.Editor;ExtraModuleNames.AddRange(newstring[]{"MyProject"});ExtraModuleNames.AddRange(newstring[]{"TestModuleEd"});// ←ここを追加}}モジュールファイルのソリューションへの追加
[MyProject.uproject]の右クリックメニューから[Generate VisualStudio project files]を実行し、ソリューションを確認し、ビルドする。
エラーが出る場合は、設定を確認する。
UEエディタにて
[ウィンドウ] -> [デベロッパーツール] -> [モジュール] に追加したモジュールが表示されます。
まとめ
機能別にモジュール分割をするように推奨されているようですが、依存関係は設計段階で考慮しないと大変なことになります。
EditorUtilityWidget などエディタ専用の機能をC++から使う場合はエディタ専用モジュールを作成は必須になります。


