Is there a method of defining a UStruct or UClass such that you can reference them inside blueprint math expression nodes? Or does the math expression node not utilize reflection in this way?
I guess the answer is no.
I know this question is a few months old but hopefully this will be beneficial to someone.
tl:dr
Give your UFUNCTION a CompactNodeTitle
of the operator or function name that you want to use, e.g.
UFUNCTION(BlueprintPure, meta = (CompactNodeTitle = "/", Keywords = "/ divide quotient"), Category = "Math|Vector3")
Alternatively, use DisplayName
instead:
UFUNCTION(BlueprintPure, meta = (DisplayName = "*", Keywords = "* multiply times product"), Category = "Math|Vector3")
How it works
I also wanted to use functions and mathematical operators on a custom USTRUCT. So I looked into the Unreal codebase. As of 4.12.5 Editor/BlueprintGraph/Private/K2Node_MathExpression.cpp
is what you’re after. Around line 804 we see:
if (TestFunction->HasMetaData(FBlueprintMetadata::MD_CompactNodeTitle))
{
FunctionName = TestFunction->GetMetaData(FBlueprintMetadata::MD_CompactNodeTitle);
}
else if (TestFunction->HasMetaData(FBlueprintMetadata::MD_DisplayName))
{
FunctionName = TestFunction->GetMetaData(FBlueprintMetadata::MD_DisplayName);
}
Add(FunctionName, TestFunction);
So, it’ll use CompactNodeTitle if present, otherwise it’ll use DisplayName. In the above examples, this allowed me to write *(V1, V2)
, and also the infix style V1 * V2
(I assume because it’s a recognised operator, see line 2172 onward of K2Node_MathExpression.cpp
).
My concern was mainly with mathematical operators but the functional style should work for any function name. See also Runtime/Engine/Classes/Kismet/KismetMathLibrary.h
for how unreal declares mathematical operations for its built-in types.