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.
Open your plugins window, and hit the "New Plugin" button on the bottom right of the plugins dialog.
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.
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.
Download and install the Microsoft Azure SDK via the installer provided on the Microsoft website here
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:
Kinect libs are in the SDK here...
Kinect headers are in the SDK here...
Create a new k4a directory alongside the ExampleLibrary content and place the header files into that to help maintain some pathing in the SDK.
Copy the dll's into the x64/Release folder
So the MyFirstTPLPLibrary\x64\Release\ folder will look like this:
Copy the libs into the same x64/Release folder
Close the Unreal project if you haven't already, and delete Binaries, Intermediate, Saved, and the .sln file...
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.
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)
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).
Make sure to add the ExampleLibraryHand2 into your MyFirstTPLP.h header file.
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
You will also have to manually copy the k4a.dll into the Binaries/ThirdParty/MyFirstTPLPLibrary/Win64/ folder here.
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
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.
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!