How can I get around some Unreal header tool limitations?

Hi,

I have attacked a problem from several different angles and now I think I have emptied my toolbox with good tools for this issue as I have hit problems with the unreal header tool every time.

I’m going to do a attribute system for a character, and I want to be able to access it nicely from blueprint.
I want to have attributes of different types, and support them all without duplicating lots of code.
My first idea was to make a FAttribute struct that is templated and have a few members variables like: OriginalValue and BuffedValue that should be accessible from blueprints.
However, I noticed that you can’t declare USTRUCT as a template. I tried to modify unreal header tools to support my FAttribute, but I noticed that I don’t have deep enough knowledge to get this fully working.

Next I tried to generate the classes with macros (ugly, I know), but then I noticed that the unreal header tools doesn’t support other than the hardcoded macros that exists.

Last angle of attack was to make a enum for each attribute, and then add a include file (IntAttributes.h) containing:

INT_ATTRIBUTE( mStrength, IA_Strength )
INT_ATTRIBUTE( mDexterity, IA_Dexterity )

and then in the header file of my character do:

enum EIntAttribute
{
#define INT_ATTRIBUTE( ATTR, VAL ) ATTR,
#include "IntAttributes.h"
#undef INT_ATTRIBUTE
};

And then my plan was to do a map in the .cpp-file the same way. And then access the attributes with getter and setters through blueprint. But here I noticed that you needed to declare the enum as a UENUM to be able to expose it to blueprint and then it didn’t read the #includes properly to generate the headers properly.

Is there any plan to extend the header-tool to support any of these patterns, or are they just considered to add unnecessary complexity and confuse users, as there is better ways to solve the same issue? If so, how would the the proper UE4 way of doing the same?

Cheers,
Markus

Hi,

Yeah, I’m afraid UnrealHeaderTool is limited to only a handful of known preprocessor constructs. What you are trying to do (so called X-macros) is a perfectly valid C++ construct and we use it in some of the engine code. However, the header tool does not do a proper preprocessor pass over the headers for historical and performance reasons and so macro expansion does not occur.

Proper preprocessor support is on our wishlist. For now, I would suggest writing a script to generate the headers for you, then UHT will preprocess those directly. Inconvenient, I know, but it’s the best I can suggest for now.

Steve

Thanks for the quick answer Steve,

Then I know that I haven’t missed any documentation about what’s possible with the UnrealHeaderTool.

I didn’t know that the macro-dance was called X-macros, I just saw it somewhere but they didn’t name it.

Cheers,
Markus

Has this changed at some point?
Facing somewhat the same issue. Having lots of upcomming repetetive code that should be wrapped by a macro. Especially code that needs to get blueprint exposed.

UFUNCTION(BlueprintCallable, Category = "Plugins|SteamGeneral")
STEAMDELEGATE_BIND(OnGameOverlayActivated, FSteamGeneralManager, FSteamDelegateOnGameOverlayActivatedDyn)

That does not work, as header tool runs first and expects a proper function below it, which is still a macro as the preprocessor did not run.

No, this has not changed, and isn’t likely to change any time soon.

Steve