#define doesn't work with UFUNCTIONS


I tried to make use of #define with UFUNCTIONS today and it seems this is not working properly. I want to remove blueprint calls for my functions on demand to use of #define is probably the best approach to make this by changing only one variable in code.

Unfortunately, when I’m adding #if #endif for the UFUNCTION macro or full function definition, it is no longer available in blueprint no matter what.

I believe it shouldn’t work that way or maybe I’m doing something wrong?

To reproduce the issue:

  1. Create simple c++ project
  2. Add custom class based on StaticMeshActor
  3. Create blueprint callable function in our actor
  4. Check if you function is accessible in the blueprint
  5. Add your #define and surround your function with #if/#endif

Any help with this issue would be appreciated.

UnrealHeaderTool that generates reflection information runs before C++ preprocessor. UHT simply assumes that every #if statement evaluates to false and generates no reflection info for these functions.

If you want these functions to do nothing on certain builds, you’d have to put the #if statements inside the functions bodies:

float AMyActor::MyBPFunction()
    /* code when turned on */
    return SomeValue;
    return 0.0f;

Thanks for the response. This doesn’t fix my issue, because functions will be still visible in blueprints but simply won’t work. But as far as I understand, there is no fix to this so I need to accept UnrealHeaderTool limitations :slight_smile:

Hello ,

What type of condition are you using for your #if statements? It could be failing the condition so that is why I’m curious. When following your repro steps, I used #if WITH_EDITOR which will result in true unless you’re working with a standalone / packaged game.

Hi ,

I’m using custom #define WITH_MY_CUSTOM_DEFINE 1. #if and #endif statements are in the same file so there is no possibility of the mistake.


I assume that WITH_EDITOR works because it is defined by UBT. Information about this is in Build.h.

Ah I see, thank you for clarifying that. I’m not familiar with using the custom #defines myself so I wasn’t quite understanding you. I see the issue now however and I’ve placed a bug in for the issue. For reference, the bug’s number is UE-28103. I’ll be sure to let you know if any changes are made to it in the future. Unfortunately, I can’t think of any workarounds for the problem at the moment besides using existing specifiers.

Hello .

After putting in this bug report, I’ve been given the information that this is a known limitation of UHT. Nothing that is inside of an #ifdef except WITH_EDITOR or WITH_EDITORONLY_DATA will be parsed by UHT. Unfortunately, this is something that you will have to work with.