How to make a 3rd Party Library Plugin for Unreal

Creating plugins for the Unreal Engine is powerful -- creating plugins that use third party libraries is even more powerful.  A key mandate of our Labs team is to repatriate software from our projects into tools, libraries, and more generalized software solutions.  A key code approach and organization in Unreal Engine development is the use of plugins to manage re-usable code.

In the steps below we will create a new plugin and add the new Microsoft Azure Kinect SDK into the plugin.
Creating plugins for the Unreal Engine is powerful -- creating plugins that use third party libraries is even more powerful.  A key mandate of our Labs team is to repatriate software from our projects into tools, libraries, and more generalized software solutions.  A key code approach and organization in Unreal Engine development is the use of plugins to manage re-usable code.

Start off by creating a new C++ project in Unreal.  We've used version 4.24 in this example.


1-start-project

Open your plugins window, and hit the "New Plugin" button on the bottom right of the plugins dialog.

2-new-plugin-2

Scroll down and choose "Third Party Library" from the new plugins menu, name your plugin (in our case MyFirstTPLP), and fill out Author, Description and URL.

4-template-name

Once complete you will notice the directory structure that is created including an a ExampleLibrary that has been placed in as an example into a ThirdParty folder.  Take a read through the code generated to get a sense of how the library is included and called by ExampleLibraryFunction() in the plugins StartupModule which is run as soon as the plugin is loaded.  Also note, instead of removing the ExampleLibrary code we have kept it in there and added our library files along-side it for simplicity and to help illustrate the patterns.

5-file-structure

Download and install the Microsoft Azure SDK via the installer provided on the Microsoft website here

6-download-sdk

Once Installed you need to copy the Azure Kinect SDK files into the correct folders in the project.  Copy the dll's and libs and headers from the installed SKD folders into the correct folders inside the plugin folder in the project.  Kinect SDK dlls are here: 

7-kinect-bin

Kinect libs are in the SDK here... 

8-kinect-lib

Kinect headers are in the SDK here... 

9-kinect-include

Create a new k4a directory alongside the ExampleLibrary content and place the header files into that to help maintain some pathing in the SDK.  

10-a-move-includes


Copy the dll's into the x64/Release folder

11-move-dll-cropped


So the MyFirstTPLPLibrary\x64\Release\ folder will look like this:
12-move-lib-cropped



Copy the libs into the same x64/Release folder

13-release-folder

Close the Unreal project if you haven't already, and delete Binaries, Intermediate, Saved, and the .sln file...

14-delete-and-regenerate

Right click the project and generate the Visual Studio project file.  This will add in all of the new files added above into the Visual Studio solutions explorer directory structure. 

15-generate-files

Add entries in the MyFirstTPLPLibrary.Build.cs file for the libs and dll's in the 3 areas shown below.  (You will notice this example is Windows only)



16-build-file

In the MyFirstTPLP.cpp file load the third party dlls by adding the code to find the location of the dll (LibraryPath2), and then load it (ExampleLibraryHandle2).

17-added-handles

Make sure to add the ExampleLibraryHand2 into your MyFirstTPLP.h header file.

18-added-headers

For simplicities sake of this tutorial place the Kinect code into the startup module.  This will run when the plugin loads during the project load.  The sample Kinect code is from the Microsoft Azure Kinect Quickstart example here.

19-added-kinect-code

You will also have to manually copy the k4a.dll into the Binaries/ThirdParty/MyFirstTPLPLibrary/Win64/ folder here.

20-added-dll-to-binary-folder

And make a minor change to the k4a.h include headers by adding MyFirstTPLPLibrary before /k4a/ in the include paths of this one file below.  Eg 

#include <MyFirstTPLPLibrary/k4a/k4aversion.h>
#include <MyFirstTPLPLibrary/k4a/k4atypes.h>
#include <MyFirstTPLPLibrary/k4a/k4a_export.h>

21-update-k4a

Build the project, and open the project file editor.  While it's loading the above example will popup a message window provided by the built in example, and then will run the Kinect code.  You can see the serial number of the device returned in the output window below.

22-serial-number-end-2


This is clearly just an illustrative first step in integrated a larger SDK but should help you get the ball rolling... or in this case the depth camera rolling! 

Dark Slope