forward declaration issue with ustructs

hi,

forward declaration works fine with UCLASS-es, but I get the following compilation error when try to do it with USTRUCT-s (e.g.: “struct FRTSPlayer;”) to use them in other USTRUCT-s:

…Unrecognized type ‘FRTSPlayer’ - type must be a UCLASS, USTRUCT or UENUM

and several other error messages are coming, pointing to lines where that struct type is used, and compilation fails.

Another strange thing comes when I modify USTRUCT() to USTRUCT(BlueprintType), then the message above appears but the compilation is completed successfully, but only when the struct is defined in the header file containing a UCLASS. if it is in a separate file it fails.

I normally add new .h/.cpp files to the project by right clicking source folder or a subfolder in solution explorer, and select add item. I also add always the #include “…generated.h” line and macros properly. Basically, everything else works fine.

Maybe I do something wrong, or it would be better to use UObject in similar cases, when they should be referenced in other UStructs?

thanks.

What do you mean by ‘use them in other USTRUCTs’?
If you mean embedding them like:



USTRUCT()
struct X
{
  UPROPERTY()
  struct A a;
};


then that isn’t possible in C++ at all. Member variables which aren’t pointers/references need to have their type fully defined.
If that’s what you’re doing, then yeah you’ll get a UHT error, but actually it’s irrelevant, since it couldn’t compile even if the UHT pass succeeded.

sorry if I was unclear, something like the following, e.g. to store a pointer in child structs to the owner struct, set by parent struct or GameMode:


USTRUCT(BlueprintType)
struct FRTSPlayer
{
    GENERATED_USTRUCT_BODY()

...

    // own units
    UPROPERTY()
    FRTSUnitManager RTSUnitManager;

...

};



USTRUCT()
struct FRTSUnitManager
{
    GENERATED_USTRUCT_BODY()

...

    UPROPERTY()
    FRTSPlayer* RTSPlayer;

...

};



Okay. Pointers to structs aren’t supported as UPROPERTYs. Structs are essentially used as value types within the UE4 property system.
If you remove the UPROPERTY() line, it should work fine with a forward declaration.

thank for the prompt answer, it works now!
I have not found info about this limitation in the docs…
now I simply have to decide whether switch to UObject or not…