"error : Unrecognized type '...' - type must be a UCLASS, USTRUCT or UENUM" even if declared just above

Hi, I have a problem with type declarations. The structure of my game led to circular dependencies (two header files including each other). So I tried to do like on this page:

Essentially, PlayerState.h and Minion.h included each other. So I did like in the wiki article linked above: I moved the #include Minion.h from PlayerState.h to PlayerState.cpp and added a forward declaration of the required struct in PlayerState.h. Now I have this:

struct FMinion;
UFUNCTION(BlueprintCallable, Server, Reliable, WithValidation)
void SetMinionTargetPosition(const FMinion* Minion, FVector TargetPosition);
virtual bool SetMinionTargetPosition_Validate(const FMinion* Minion, FVector TargetPosition);
virtual void SetMinionTargetPosition_Implementation(const FMinion* Minion, FVector TargetPosition);

However, now I get the following error:

error : Unrecognized type 'FMinion' - type must be a UCLASS, USTRUCT or UENUM

Is there a way to avoid both this error and circular includes? Note that I don’t get the error when I comment out the UFUNCTION line.

I think you should make the opposite you did: in Minion.h make a forward declaration of your PlayerState class and move PlayerState.h to Minion.cpp. And just include normally Minion.h in PlayerState.h.

I tried, but I get a similar error. A header included by Minion.h depends on a struct defined in PlayerState.h. This struct is defined with “USTRUCT(BlueprintType)” in PlayerState.h and included with “UPROPERTY(Transient)” in the other header. So the forward definition doesn’t seem to work.

I’m thinking I should move the struct to a new header file and include that file in PlayerState.h and the header included by Minion.h. Is there a better way?

As for me, I usually put structs in separate header - I have no problems even with USTRUCT(BlueprintType).

I moved the struct in a separate header but then ended up with another cryptic error message:

EXEC : error : Couldn't find parent type for 'BattlePlayerState' named 'APlayerState' in current module (Package: /Script/MyGame) or any other module parsed so far.

Searching for this online leads to forum posts where people have simple syntax mistakes hidden somewhere else in their code or circular dependencies (the root of all my problems!). Some other posts suggest the Unreal Header Tool has bugs and is not able to parse the header files properly, as including the same header twice (once indirectly through another header and once directly) solved their problem.

Anyway, to anyone stuck with a similar problem in the future, I found out yesterday that my problem was actually a comment. While moving stuff around to other files, I commented out a block (planning to clean up after I make sure everything works) and it looked like this:

/*
[...]
//*/

Visual Studio only showed the text from /* to */ in green. It looked like what followed was not commented out. However it seems the UHT/preprocessor/compiler (not sure which part is involved for that step) saw //*/ as being */ commented out and considered the rest of the file to be commented out. So changing the above block to

/*
[...]
*/

got rid of my problem (now I have other compiling errors, but at least these ones make sense and are easy to fix).