In this case you supposed to define functions in another “blueprint functions library” class, as statics with MyStruct
as param. Not sure about exact rules, but being first param and const ref
is surely works
So, i’d write your example in following way:
#include "Kismet/BlueprintFunctionLibrary.h"
USTRUCT()
struct FMyStruct
{
GENERATED_BODY()
UPROPERTY(BlueprintReadWrite)
float a;
UPROPERTY(BlueprintReadWrite)
float b;
float Add() const {
return a + b;
}
}
UCLASS()
class UMyStructStatics : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, DisplayName = "Add")
static UPARAM(DisplayName="Result") float BP_Add(const FMyStruct& MyStruct)
{
//you may write the implementation directly here, but i think it's better to keep it in native struct so they still can be easily used in native code
return MyStruct.Add();
};
}
This way you’ll be able to select Add
function from the drop down list as if it was an FMyStruct’s function