Due to my company needs, I am to see if it’s easy to work with third party dlls (we have much of them and would like to plug them in the engine).
So I try the third party library plugin template (with the ExampleLibrary printing “Hello world” at plugin load).
My problem is I’m not able to get my change in example library (printing “hellow world 2” instead of “Hello world”) to be reflected in the editor :
- Changing the exampleLibrary.cpp from Plugin project and rebuilding plugin project (from vs or ue4 editor) seems to do nothing about the ExampleLibrary dll
- Changing ExampleLibrary.cpp from ExampleLibrary sln (in another vs), and rebuilding it (in the other vs) give me an error at postbuild when the dll is copied into project thirdparty folder :
error MSB3073: command "copy
stop with error code 1.
I guess ExampleLibrary.dll is always loaded by ue4 editor (an so , is write protected)
So my question is :
what is the best way to get external library change reflected in editor ?
I hope it is not mandatory to close ue4 in order to build external library
I found something interesting (I don’t know why unreal does not already do that in the template) :
After FPlatformProcess::FreeDllHandle(ExampleLibraryHandle); (in FMyPluginModule::ShutdownModule) add this :
And then the third party library will really be unloaded from memory, and can be replaced when the post build of the third party library occurs.
Headers needed :
reference for delay unload on windows :
Best solution I came to to manage third party loading and unloading (including dependencies) :
#define LOCTEXT_NAMESPACE "FMyPluginModule"
int firstLoad = true;
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
// Get the base directory of this plugin
FString BaseDir = IPluginManager::Get().FindPlugin("MyPlugin")->GetBaseDir();
// Add on the relative location of the third party dll and load it
LibraryDir = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/MyPluginLibrary/Win64/"));
LibraryPath = FPaths::Combine(*LibraryDir, TEXT("ThirdPartyLoader.dll"));
if(!firstLoad) ExampleLibraryHandle = LoadLibrary(*LibraryPath);
firstLoad = false;
ExampleLibraryHandle = GetModuleHandle(*LibraryPath);
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
// Free the dll handle
This only works for windows.
Dlls of third party library and all its depencies must be copied into the plugin third party binaries directory.