在UE4中使用Module
来源:互联网 发布:生猛海鲜知乎 编辑:程序博客网 时间:2024/06/04 17:53
1.新建UE4项目(with cpp)
//非cpp项目,直接新建cpp文件也可以
//编译后重新打开UEEditor可以看到
2.新建第二个Module
1)文件目录如下:
2)代码如下:
OtherModule.Build.cs
using UnrealBuildTool;public class OtherModule : ModuleRules{ public OtherModule(TargetInfo Target) { PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" }); }}
OtherModule.h
#pragma once#include "Engine.h"#include "ModuleInterface.h"class IOtherModuleInterface : public IModuleInterface{public: virtual int Add(int num1,int num2) =0; virtual void doNothing() =0;};
OtherModule.cpp
#include "OtherModule.h"class OtherModuleImpl :public IOtherModuleInterface{public: virtual void StartupModule() override { } virtual int Add(int num1, int num2) override { return num1 + num2; } virtual void doNothing() override { }};IMPLEMENT_GAME_MODULE(OtherModuleImpl, OtherModule);
3.在MainModule中使用
1)在MainModule.Build.cs中增加依赖
public MainModule(TargetInfo Target) { PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay" }); PrivateDependencyModuleNames.AddRange(new string[] { "OtherModule"}); }
2)在其他的任意类中使用(此处使用一个actor)
#include "OtherModule.h"// Called when the game starts or when spawnedvoid AMyActor::BeginPlay(){ Super::BeginPlay(); if (GEngine) { IOtherModuleInterface* OtherModule = FModuleManager::LoadModulePtr<IOtherModuleInterface>("OtherModule"); if (OtherModule != nullptr) { OtherModule->doNothing(); GEngine->AddOnScreenDebugMessage(-1, 20, FColor::Yellow, FString::FromInt(OtherModule->Add(1, 2) + 2)); } GEngine->AddOnScreenDebugMessage(-1, 20, FColor::Yellow, FString("hello_AMyActor222")); }}
4.在vs中右键Build,在UE4中compile并run
其他:
1)GEngine报错,请将MainModule.h中的include文件改为“Engine.h”;
2)如果vs编译和ue4compile没有错误,但是没有打印结果(LoadModulePtr为空),请将UEEditor关闭重开,弹出对话框是否重新编译OtherModule.lib,选是,这时候就能打印结果了。
3)virtual void doNothing() =0;表示该函数为声明函数,只有子类实现,去掉OtherModule.cpp无法编译
4)OtherModule.h中的IOtherModuleInterface和OtherModuleImpl必须是分离的,不然编译不通过。
这也说明,lib中暴露的函数必须都放在IOtherModuleInterface中。
5)如果修改lib中的内容,有时候需要rebuild而不是build。
6)参考网址:
http://blog.csdn.net/jack0596_cn/article/details/52387890
https://forums.unrealengine.com/showthread.php?65944-c-Mysql-database-error&highlight=mysql
https://www.youtube.com/watch?v=piPkLJerpTg
https://docs.unrealengine.com/latest/INT/Programming/Modules/Gameplay/
- 在UE4中使用Module
- UE4 在游戏中使用Slate
- SpeedTree - 在UE4中使用模型
- 在XQuery中使用Module
- Butterknife 在module中使用
- 在module中使用Alert出错
- 在Flex4的Module中使用Alert
- UE4在场景中使用预计算可视性(PrecomputedVisibility)
- UE4:C++中使用材质
- UE4中使用自定义log
- 在OpenCV for Android 中使用SURF(nonfree module)
- 使用 IDEA 在一个 Project 中创建多个 module
- UE4 LevelSequence 在蓝图中播放
- ue4在Xcode中没有代码提示
- 在UE4中改变枢轴位置
- UE4在C++中动态加载资源
- C++,在UE4中写Hello World!!
- [UE4]注意事项,插件中蓝图方法库在C++中的使用
- Fragment在生命周期中是如何走到onCreateView的(一)
- 织梦系统(DEDECMS)后台模板修改3
- 微信小程序实战 《跨时空》旅行日记小程序
- 343. Integer Break 类别:动态规划 难度:medium
- mysql免安装版1067错误终极解决办法
- 在UE4中使用Module
- A child container failed during start,Caused by: java.lang.ClassNotFoundException
- 操作系统总结(七)死锁
- 《生活中的脚本》- 过年回家如何省钱地给孩子们发红包~
- LibSVM for Python 使用
- 【编程之美】之初探Struts1
- jQuery_属性过滤选择器
- 62. Unique Paths 类别:动态规划 难度:medium
- PAT-甲级-1007