Hello everyone! I got such a problem. How can I trigger an event when a file changes? I know that I need to use the “DirectoryWatcher ”, but I don’t understand how exactly I should do it. What should the constructor look like for everything to work as it should?
In the screenshot you can see my attempts to make this work…
private:
static FDelegateHandle WatcherHandle;
cpp:
static FDirectoryWatcherModule &DirectoryWatcherModule = FModuleManager::LoadModuleChecked<FDirectoryWatcherModule>(TEXT("DirectoryWatcher"));
FDelegateHandle FMyClass::WatcherHandle = FDelegateHandle();
DirectoryWatcherModule.Get()->RegisterDirectoryChangedCallback_Handle
(
MY_FOLDER_PATH
, IDirectoryWatcher::FDirectoryChanged::CreateRaw
(
this, &FMyClass::OnProjectDirectoryChanged
)
, FMyClass::WatcherHandle
, IDirectoryWatcher::WatchOptions::IncludeDirectoryChanges
);
void FMyClass::OnProjectDirectoryChanged(const TArray<FFileChangeData> & Data)
{
// ... do stuff
}
1 Like
You should try create the static handle on global scope and register the callback in a class constructor instead of doing that.
And your directory should be an absolute path, not relative.
I use that code on a few editor extensions and works just fine.
Shark_vil
(Shark_vil)
June 13, 2020, 9:40am
5
BrUnO XaVIeR:
You should try create the static handle on global scope and register the callback in a class constructor instead of doing that.
And your directory should be an absolute path, not relative.
I use that code on a few editor extensions and works just fine.
Ok, I’ll try to do it, thanks. )