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:
Create simple c++ project
Add custom class based on StaticMeshActor
Create blueprint callable function in our actor
Check if you function is accessible in the blueprint
Add your #define and surround your function with #if/#endif
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()
{
#if COMPILE_TIME_CONDITION
/* code when turned on */
return SomeValue;
#else
return 0.0f;
#endif
}
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
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.
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.
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.