Problems with circular references and FRunnable

Hi,

I’m trying to offload some work in my project to a new thread using an FRunnable based on this tutorial: https://wiki.unrealengine.com/Multi-Threading:_How_to_Create_Threads_in_UE4, but I’m running into all kinds of dependency problems.

So I have two classes: “AFowManager” which is responsible for spawning a “AFowWorker”. The headers look like this:

#include "GameFramework/Actor.h"
#include "FowManager.generated.h"
    
    UCLASS() 
    class RPGTEST_API AFowManager : public AActor
    {
    	GENERATED_BODY()
    ...
           AFowWorker FowThread;
    ...
    }

**************
class AFowWorker : public FRunnable
{	
	//Pointer to our manager
	AFowManager* Manager;

So the FowManager needs to spawn the thread and it includes a pointer to itself which is fed into the constructor. I’ve tried to let the two classes include each other, I’ve tried adding both of the .h-files to the MyProject.h-file and included it in both of the headers, I’ve tried making a foreward declaration to the AFowWorker-class in the AFowManager-header, but I’m getting different permutations of the errors:

FowManager.h(76) : error C2079: ‘AFowManager::FowThread’ uses undefined class ‘AFowWorker’
FowManager.h(75) : error C2146: syntax error : missing ‘;’ before identifier ‘FowThread’
FowManager.h(75) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

The “funny” thing is that I do have other classes referencing each other, but these are all UCLASS()-annoted, whereas I’m getting a “Superclass not found”-error if I try annoting my FRunnable with a UCLASS.

If anybody would care to share some light on the matter it would be greatly appreciated.

So I made this work, though I still don’t understand why exactly. Anyways the solution was to include the “FowWorker.h” in the FowManager’s header and make a foreward declaration of the FowManager in the FowWorker’s header. Don’t know why it didn’t work out the other way around. The resulting headers are:

#include "GameFramework/Actor.h"
#include "FogOfWarWorker.h"
#include "FogOfWarManager.generated.h"

UCLASS() 
class RPGTEST_API AFogOfWarManager : public AActor
{
	GENERATED_BODY()
...
       AFogOfWarWorker* FowThread;
...
}

*******************
class AFogOfWarManager; //Forward declaration

class AFogOfWarWorker : public FRunnable
{	
	//Pointer to our manager
	AFogOfWarManager* Manager;
}