The Rider expands the UE macro incorrectly

USTRUCT()
struct FStructss
{
    GENERATED_BODY()
    
};

#define DEFINE_RESOURCE_LOGIN_REQUEST(StructName, DataType) \
USTRUCT()\
struct StructName \
{ \
    GENERATED_BODY()\
    int32 code; \
    FString msg; \
    TArray<DataType> data; \
};

DEFINE_RESOURCE_LOGIN_REQUEST(FLoginRequestm,FStructss)

In the above code, I declared my struct by using a macro, which looks all good.
However, Rider incorrectly replaces USTRUCT() or GENERATED_BODY() with __resharper_ue4_ustruct() and __resharper_ue4_generated_body().

__resharper_ue4_ustruct()
struct FLoginRequestm
{
    __resharper_ue4_generated_body()
    int32 code;
    FString msg;
    TArray<FStructss> data;
};

This causes a compilation error.

Other related links:
https://forums.unrealengine.com/t/why-macros-like-usturct-cant-be-wrapped-by-custom-macros/2325097?u=bssnake

I didn't find the feedback button, but I found it here and would appreciate a response from the developers. Thanks.

0
1 comment

Hello Bssnake,

This code doesn’t compile because not because of Rider. The issue in code lies in the improper use of Unreal Engine’s reflection system macros and how the Unreal Header Tool (UHT) processes them.

Reflection Macros are different from C++ Preprocessor Macros. UHT scans for these reflection macros to generate crucial boilerplate code for Unreal’s reflection system and object-processing systems BEFORE the C++ preprocessor does his job. So, nothing under “#define” is expanded at the moment of UHT work.
These macros only function correctly when they are directly present in the source code, as UHT does not expand or interpret custom preprocessor macros.

In other words, when UHT process such a code it does not evaluate or expand macros:

#define DEFINE_USTRUCT(Name) \
USTRUCT() \
struct Name { GENERATED_BODY(); };

DEFINE_USTRUCT(FMyStruct);

it only sees this

DEFINE_USTRUCT(FMyStruct);

It has no knowledge of what DEFINE_USTRUCT means because the macro expansion is handled later by the C++ preprocessor, which UHT does not interact with

Hope that explains the issue.

1

Please sign in to leave a comment.