Abstract
In this page, I will describe about making Plugin for Unreal Engine 4. This will include how to create blank plugin and decorate for linking system library(in this case, location base service, etc). Target UE4 version is 4.21 and (of course) you need that version of UE4 and make sure AndroidWorks is install in order to support Android build or iOS build environment(for iOS build).
Simple Plugin Creation – build tool in UE4 Editor
Below steps are usually used in old version(maybe around 4.16?). So please look at it just legacy referencing.
Most simplest method to create plugin(empty structure) is using UE4 Editor’s Plugin Template. To do this, after launching UE4 editor, go to Edit – > Plugins -> Examples(left panel). There are several examples. Let us choose ‘Blank Example Plugin’.
Most simplest method to create plugin(empty structure) is using UE4 Editor’s Plugin Template. To do this, after launching UE4 editor, go to Edit – > Plugins -> Examples(left panel). There are several examples. Let us choose ‘Blank Example Plugin’.
Be sure to click ‘Edit’ before ‘Restart Now’. You can modifies several options likewise Icon, name, category, etc. By defining custom category, you could organize plugin group. After restarting, your first blank example plugin is ready to set(actually it already created in {UE4 Engine Root}/Engine/Plugins/Developer/BlankPlugin).
Fig 2. shows basic and essential Plugin directory structure. It contains uplugin(essential plugin declaring file), cs file(build script used by UnrealEngine Build Tool), Resources(icon, in this case), and source codes(public for external exposed header and private for logic). Let’s take a look more deeply.
uplugin file
This file contains meta data for plugin. it includes name, category(do you remember the ‘edit’ button mentioned right before clicking ‘Restart Now’ button?). Moreover there is Modules section declaring and controlling module loading time. For more details about loading phase, please refer to UE4 AnswerHub.
Build.cs file
This Build.cs file is regular build meta file in UE4 world. It contains header files location, external dependencies. Also further more, please refer to UE4 documentation page.
PlugIn – Directory
Plugin could be positioned at Engine directory or content directory. If it is required by global scope or at the time the engine is loaded, then use engine directory. If it is needed by content code(your code), then position it in user content directory.
Wherever it is positioned, the basic directory structure are same as below if it is Engine Plugin.
The rule is,
{engine or content root} / Plugins / {category} / {Plugin Name} / …
And, if it is not for Engine Plugin, says if Project Plugin, this will located in project directory like below,
as you can see, project plugin’s directory structure is same as Engine plugin’s. So once creating plugin via Editor’s plugin creation, you may move its directory from engine to project as like Fig 4.
Fortunately UE4 editor provides more detailed plugin creation template nowadays. You don’t need to move directory anymore.
As shown in Fig 5, it provides lots of options for creating. you could specify whether it is engine or project plugin or need to exposing content directory to plugin. Base on your selection, engine will create starting codes.
Now, Let’s dig more deeply.
we will make plugin which is reporting wifi signal strength and location axis. This functionality is provided by UE4 engine level, but making own will be good practice.
Plugin name is ‘TestSample’ and it will be project plugin. UE4 4.21 is used and it will referencing some external library of android/iOS system.
Preparing plugin skeleton
Please follow Plugin creation procedure for life hack. it will generate all skeletal codes just a few clicks. Let’s choose Blank.
2 files are created, TestSample.h and TestSample.cpp and its main purpose is the initial hooking point for bringing up the module.
class FTestSampleModule : public IModuleInterface
{
public:
/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
};
As the function name says, StartupModule and ShutdownModule is called on starting or finishing module. Your very first code will be placed here. Now, let’s design some code referencing. This plugin will referencing iOS or Android system library in single entry point. So wrapping is required and platform dependent predefinition will be declared.
Module will reference Service Provider class which is wrapping platform dependent libraries. so the plugin module could call single entry point for each platform implementations.
Defining Service & Interfaces
Function Name | Description | Misc. |
OnTestSampleStart | initialize service | |
OnTestSampleStop | shutdown service | |
OnWiFiSignalStrengthChanged | delegate for WiFi signal strength changing | |
OnLocationChanged | delegate for Location changing |
PlugIn Skeleton
(before starting, you may use above blank plugin template(?).
Plugin Name | TestSample |
Location | contents area |
File Info
TestSample.h/cpp | Plugin main module header/source |
TestSampleProvider.h/cpp | accessing class for wrapper |
TestSampleWrapper.h/cpp | Wrapping class for accessing iOS/Android functions |
TestSampleBlueprintLibrary | exposes to Blueprint |
TestSample_APL.xml | APL build script(?) file for Android api referencing |
TestSample_iOS.h/cpp | file for iOS referencing |
Start Module – TestSample.h/cpp
BlueprintLibrary
APL & JNI – Android
JNI Type Signatures
Ref to this page.
It describes about JNI type signatures.
Defining External Library – iOS
Referencing External Functions in PlugIn
Misc.