Header file doesnt see included struct from another header file

I have a header file where I declared a struct:

USTRUCT(BlueprintType)
struct FHnsLobbyInfo
{
	GENERATED_BODY()

public:

	UPROPERTY(BlueprintReadWrite)
	UTexture2D* MapThumbnail;
	UPROPERTY(BlueprintReadOnly)
	TArray<FString> PlayerList;

};

Then I include this header file in another header file where I want to use it in a delegate:

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FLobbyUpdated, struct FHnsLobbyInfo, FOnLobbyUpdated);

And the compiler gives me this error

Error: Unrecognized type 'FHnsLobbyInfo' - type must be a UCLASS, USTRUCT or 
UENUM

I tried including the header file in different places (above or below other includes) but nothing seems to work. No problems in the header file where I declare it, and no errors there.

Is it possible that the editor tries to compile the header file with the delegate before it compiles the file with the struct? I did some research but nothing worked, rebuilt the project files several times, tried other names, tried it with and without struct in the delegate, tried not using USTRUCT(BlueprintType) but nothing.

What could be the problem?

Remove the struct keyword in dynamic delegate declaration.

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FLobbyUpdated, FHnsLobbyInfo, FOnLobbyUpdated);

Struct keyword is for declaring a new struct type, or forward-declaring it. If you already have/included its declaration, you don’t need to redeclare it.

Remove the struct keyword in dynamic delegate declaration.

I added that struct after I tried it without it, this was one of those things I tried.

I just tried using an other header file’ struct, and the exact same error happens.
Even if I use the delegate in another file.

This error is from UHT not from C++ compiler.

Did you include the corresponding *.generated.h in the struct header file ?

What do you mean? The header file’ own generated.h file? Or there is separate struct generated.h file?

SOLVED!

It was simply forward declaration! I had 5 circular dependency errors when the project compiled, it still launched before, but now it had probably more fatal errors wih the headers.

For those who might run into this (or for myself if I mess it up again):
So you might included some header files in each other, and what happens is that the UnrealHeaderTool cant decide exactly which file to compile first, so some data may not even be accessible or it will be but just not in the right order which might lead to the same thing, some variables (or something else) will be undefined/inaccessible.

To fix this, first, when compiling check for circular dependency errors, if there is any, search for them and remove them from unecessary header files. (there are includes that you should not include in the header, instead in the CPP (I always included every header in the header files, never in CPPs, and thats sometimes a mistake, sometimes you need other header files only in the CPP))

It looks like this:

Second, in some header files where you had circular dependency error, you might need to use forward declaration like this:

/*dont include ATest header here if you had circular dependency error before, you might just need forward declaration like below, test it */
#include "HnsBeaconClient.generated.h"

//forward declaration
class ATest;

And, all this solves my original error with the delegate that didnt find my struct from another file, it was probably inaccessible :smiley:.

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FLobbyUpdated, FHnSLobbyInfo, FOnLobbyUpdated);

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.