Expose struct operators to Blueprint

Hey there, happy to answer this!

Most (In fact I think all) of the binary operators in Blueprint are written in quite a similar way. Let’s take FVector as an example.

FVector declares FVector FVector::operator*(float Scale) const in Vector.h, and UKismetMathLibrary declares the following static method which is exposed to Blueprint in KismetMathLibrary.h:

/** Scales Vector A by B */
UFUNCTION(BlueprintPure, meta=(DisplayName = "vector * float", CompactNodeTitle = "*", ScriptMethod = "MultiplyFloat", ScriptOperator = "*;*=", Keywords = "* multiply"), Category="Math|Vector")
static FVector Multiply_VectorFloat(FVector A, float B);

The implementation of this static method is simply return A * B;.

Really, this is all you need. But you probably also want to make the node look and behave like the other operator nodes in Blueprint. To do that, you’ll need to make sure you have these three Specifiers in you UFUNCTION macro’s Meta=():

  • DisplayName: Human readable friendly name. This is what appears in the Blueprint context search
  • CompactNodeTitle: This is what makes the node appear like all the other operator nodes you’re already familiar with
  • Keywords: A space separated list of words to help this node show up in a context search

CompactNodeTitle is the one you need for this to work, but DisplayName and Keywords will make yours (or your designers) life easier too!

That should be it, hope this helps!

P.S. For anyone wondering, ScriptMethod and ScriptOperator expose the method to Python as a member method of the FVector type

2 Likes