Blueprint function taking double for UE5 not possible in code targetting both UE4 and UE5

I have a plugin codebase that supports both UE4 and UE5. I have custom Blueprint nodes implemented in C++ that use blueprint library class functions. I need to add support for nodes with wild inputs to take doubles in UE5 as well as floats (UE4 and UE5) which call through to the appropriate library function. The base version (UE4) has a library function, SetFloatValue taking a float parameter that gets invoked from a Call Function internal node in my custom node implementation to handle a float wired up to one of it’s inputs. To support double input values (in UE5) I need to have an function, SetDoubleValue, taking a double parameter that gets invoked (as before) when a double input is wired up. Some of the node code needs to be switched on a #if ā€˜version check’ to use the new UEdGraphSchema_K2::PC_Real type with UEdGraphSchema_K2::PC_Double/Float sub-types, but that works fine. However, the problem comes with the library function; In UE5 I need a function declared as UFUNCTION(BlueprintCallable…) taking a double parameter. But this is not supported in UE4, and I can’t use a #if ā€˜version check’ around it because: ā€œerror : UFUNCTION must not be inside preprocessor blocks, except for WITH_EDITORONLY_DATAā€ . So, my question is how can I support this cross compatibility?

I’m not really good with C++. But can You use different Headers for different UE versions? And include them conditionally?

Have you checked if it is possible to use an alias instead of float or double inside the ufunction parameters?

1 Like

I’m not sure if you can do that is it’s a structural change in code of UFUNCTION() macro.

One way I would try is creating a custom USTRUCT for my needs. Since I don’t know what your goal is with this, I can’t really recommend any more than a concept. Sorry :frowning:

Interesting suggestion. So rather than passing in explicitly double or float, you pass in your custom USTRUCT, which essentially is just a typedef on a double or float?

Crazy convoluted way to do it but if you absolutely must support UE4 and it won’t allow you to put the function definition inside C++ preprocessor tags, this effectively lets you do the same thing, it just moves the conditional preprocessor stuff to a new custom type rather than to that particular function.

1 Like

I did try that, yes, a typedef switched between float/double didn’t work as the header tool doesn’t analyse typedefs and takes the parameter types literally. :frowning:

So, fixed struct but conditional float/double member? This might work, but would really complicate the custom note building logic as I’d have to include struct creation nodes and might end up with the same problem of wiring them up via functions that are conditionally needed. It really shouldn’t be neccessary, I think the header tool should understand engine version checks as they aren’t subject to change within the working context of any single project :frowning: