Loading DLLs from Plugins

Hi guys,

I am in the process of creating a plugin that will load the Mono runtime, and allow scripting of the Unreal Engine using any Mono-supported CIL language.

I have this process running successfully, however I am looking to now clean the package up somewhat. Namely; I wish to provide all required third-party libraries within the plugin folder structure.

For example:

Is there a system in place within the plugin architecture to allow me to define the search path for loading of required third-party libraries?

I would rather not pollute the binaries (or Third Party!) directory with additional DLLs exclusively for my plugin if at all possible.

Thanks! :slight_smile:

Update: This has been addressed in 4.8. See my other answer!


This is a great question, and you’re not the first person to ask :slight_smile:

The bad news is that, currently, you have to manually copy the third party DLLs into the ThirdParty or Engine/game Binaries directory. This will, as you pointed out, pollute those directories.

The good news is that this is on our radar. We already have a TTP for it, and we will try to fix this as soon as possible. The goal is to allow for third-party DLLs in the plug-in’s Binaries directory or some other directory inside the plug-in folder, so that plug-ins are completely self contained.

Thank you for this update. I have been using the third party directories currently, but knowing there are plans for this is a very good thing in my opinion. :slight_smile:

Had a discussion about this yesterday with some other folks, and the plan is to have this fixed for 4.5.

I did this, putting my custom DLL in Binaries/ThirdParty, and that works in the editor. But when I try to cook my game and run a packaged build, or launch from editor, it does not copy the DLL over and fails to run. I see that third party DLLs for Ogg Vorbis and PhysX get copied into the packaged build automatically, but I can’t tell how this is done or what they are doing differently. The only way I can get it to work is to manually copy the DLL over every time I package a build.

edit: I figured it out. There is a monolithic automation script that I needed to add my dll to, In XPlatform.Automation.cs GetFilesToDeployOrStage. To save pollution this also involved adding a bUsingX flag to the ProjectParams, and having my game target config set it to true.

Any update on this? Is there something in 4.5 or 4.6?

I would second on this, also is there a workaround or a build step that you can attach to? Manually copying the needed dlls is quite a burden.

I am currently struggling with this same issue. Has there been a solution that hasn’t been linked here? Has there been a decision to not include this functionality? It would be good to get an update of any kind after such a long period of silence.

This has been addressed for 4.8!

It is now possible to include third-party dependencies directly in the plug-in folder without having to manually copy them to the Engine directory. I have attached a ZIP file that contains a sample plug-in project, which includes a fake third-party module in the form of full source code. Having source code for the dependency is generally preferred, because developers can then simply compile everything for whatever platform they need.

However, source code is not always available. In many cases you only have a pre-compiled DLL or Dylib that you wish to include. Those, too, are supported in plug-ins now. The attached example does not currently show this workflow, but I have attached a second file from a VLC plug-in that I am currently working on. I hope to have the entire code on GitHub later today or tomorrow - then you can take a close look at how it’s done.

The main trick for pre-compiled libraries is the RuntimeDependencies array, which is used to tell UBT about those third-party libraries. When packaging a project, those files will then automatically be included.

Another complication that sometimes arises is that DLLs have to be bound dynamically at run-time (especially when LGPL licensed), i.e. via LoadLibrary(), GetProcAddress() and similar mechanisms. This can be accomplished with FPlatformProcess::GetDllHandle() and passing in the path to the plug-ins third party directory. For example, I use the following to get the correct path in my VLC plug-in:

const FString BaseDir = IPluginManager::Get().FindPlugin("VlcMedia")->GetBaseDir();
const FString VlcDir = FPaths::Combine(*BaseDir, TEXT("ThirdParty"), TEXT("vlc-2.2.2"));

I will update this answer when I have the VLC code checked in. Then you can look at a working example.

This is now supported in 4.8. I have added another answer.

Whoops, it still is telling me the DLL is missing for the game builds. Editor build works though.
Looking forward to that example.

I have not tried this with a packaged build yet, so it may not actually work as expected. I will check with the UBT owner on Monday.

This method does not copy my DLL into the binaries directory when I package a dedicated server. Not sure about any other target. If I give it a bad source path then the packaging fails, but if I give it a good path then it doesn’t copy the DLL.

You’re missing the RuntimeDependencies settings in your Build.cs. That will copy the files to the target when packaging.

But I do have it in there.
RuntimeDependencies.Add(new RuntimeDependency(ModuleDirectory + “\DLL\libzmq.dll”));
I tried doing it from my third party library and the plugin that uses it. Neither worked.