Operator overloaded in C++ not accessible in blueprints

Hi,

I have a custom struct declared in C++ where I’ve overloaded a bunch of operators like +, -, etc.

The operators work fine in C++, however they’re not visible to Blueprints. Is this a known limitation of UE4’s or am I declaring them wrong?

USTRUCT(BlueprintType)
struct FManaStore
{

// ...variable declarations, blablabla...

	FORCEINLINE struct FManaStore& operator+=(const FManaStore& rhs)
	{
		WhiteMana += rhs.WhiteMana;
		RedMana += rhs.RedMana;
		PurpleMana += rhs.PurpleMana;
		BlueMana += rhs.BlueMana;
		return *this;
	}

// ...some more blabla...

};

FORCEINLINE FManaStore& operator+(FManaStore lhs, const FManaStore& rhs)
{
	return lhs += rhs;
}

Blueprints not only does not support operator overloading, they don’t support operators at all, those are normal node functions with special meta specifier to change there appearance “CompactNodeTitle”

https://github.com/EpicGames/UnrealEngine/blob/1d2c1e48bf49836a4fee1465be87ab3f27d5ae3a/Engine/Source/Runtime/Engine/Classes/Kismet/KismetMathLibrary.h#L249

Here part of integer functions from that header file:

//
// Integer functions.
//

/* Multiplication (A * B) */
UFUNCTION(BlueprintPure, meta=(DisplayName = "integer * integer", CompactNodeTitle = "*", Keywords = "* multiply", CommutativeAssociativeBinaryOperator = "true"), Category="Math|Integer")
static int32 Multiply_IntInt(int32 A, int32 B);

/* Division (A / B) */
UFUNCTION(BlueprintPure, meta=(DisplayName = "integer / integer", CompactNodeTitle = "/", Keywords = "/ divide division"), Category="Math|Integer")
static int32 Divide_IntInt(int32 A, int32 B = 1);

/* Modulo (A % B) */
UFUNCTION(BlueprintPure, meta=(DisplayName = "% (integer)", CompactNodeTitle = "%", Keywords = "% modulus"), Category="Math|Integer")
static int32 Percent_IntInt(int32 A, int32 B = 1);

/* Addition (A + B) */
UFUNCTION(BlueprintPure, meta=(DisplayName = "integer + integer", CompactNodeTitle = "+", Keywords = "+ add plus", CommutativeAssociativeBinaryOperator = "true"), Category="Math|Integer")
static int32 Add_IntInt(int32 A, int32 B = 1);

So you need to create your own nodes same way.

2 Likes

Thanks , seems I’d glanced over that one.