I’m using the IDirectoryWatcher module on my project to monitor changes on a directory and when packaging it, I ran into a number of issues.
Attempt 1:
If I simply add the #include "DirectoryWatcherModule.h"
and #include "IDirectoryWatcher.h"
to my .cpp files, the game in the editor works fine but I get the following error:
C:\Users[…]\Unreal Projects\MDV\Project4\MDVProject4\Source\MDVProject4\Controller\AMyController.h(6): fatal error C1083: Cannot open include file: ‘IDirectoryWatcher.h’: No such file or directory
Attempt 2:
If I add the module to the .Build.cs file as follows:
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput", "DirectoryWatcher" });
the game works fine in the editor but shows the following error when packaging:
Missing precompiled manifest for ‘DirectoryWatcher’, ‘C:\Program Files\Epic Games\UE_5.3\Engine\Intermediate\Build\Win64\UnrealGame\Development\DirectoryWatcher\DirectoryWatcher.precompiled’. This module was most likely not flagged for being included in a precompiled build - set ‘PrecompileForTargets = PrecompileTargetsType.Any;’ in DirectoryWatcher.build.cs to override. If part of a plugin, also check if its ‘Type’ is correct.
Note: I tried adding the module with DynamicallyLoadedModuleNames.Add("DirectoryWatcher");
, but got the same error.
Attempt 3:
Now things get funny. I can’t add the module and without it, it does not seem to find it. So I took the DirectoryWatcher folder from the engine and copied it into the Plugins folder of my project. The .Build.cs module added in attempt 2 was removed.
I changed the includes to
#include "../../MDVProject4/Plugins/DirectoryWatcher/Public/IDirectoryWatcher.h"
and
#include "../../MDVProject4/Plugins/DirectoryWatcher/Public/DirectoryWatcherModule.h"
to make sure the code used is that of my Plugin folder and not the one from the engine.
With this the game works fine in the editor and can package, but I get a black screen with the following error when opening the .exe file:
Assertion failed: Module [File:D:\build++UE5\Sync\Engine\Source\Runtime\Core\Private\Modules\ModuleManager.cpp] [Line: 397] DirectoryWatcher
Looking at the logs, I can see that it points to a specific line on my code that contains:
FDirectoryWatcherModule &DirectoryWatcherModule = FModuleManager::LoadModuleChecked<FDirectoryWatcherModule>(TEXT("DirectoryWatcher"));
IDirectoryWatcher* DirectoryWatcher = DirectoryWatcherModule.Get();
The reason for this is because despite the IDirectoryWatcher
and FDirectoryWatcherModule
class being used is the one from the Plugin folder, for some reason the Get()
method being used is the one from the engine.
I then tried some nasty things that I will not go into detail but the issue persists.
Unreal Engine version 5.3. Packaging mode used Developer.
I’m aware the IDirectoryWatcher module is inside the Developer folder (/Engine/Source/Developer
), but I would expect a Developer packaging mode to work with it.
How can I fix this?