UMG Viewmodel 5.1 plugin MVVMViewModelBase TMap property compile error

I’m attempting to create a viewmodel that has a TMap property using the 5.1 version of the UMG Viewmodel plugin.

.h file

UPROPERTY(BlueprintReadWrite, FieldNotify, Setter)
TMap<FName, float> MyParams;

void SetMyParams(TMap<FName, float> NewValue);

.cpp file

void UZRUIAbilityViewModel::SetMyParams(TMap<FName, float> NewValue)
{
	UE_MVVM_SET_PROPERTY_VALUE(MyParams, NewValue);
}

The macro uses the following template function in MVVMViewModelBase.h which is where I get the compile error listed below:

template<typename T, typename U>
bool SetPropertyValue(T& Value, const U& NewValue, UE::FieldNotification::FFieldId FieldId)
{
	if (Value == NewValue)
	{
		return false;
	}

	Value = NewValue;
	BroadcastFieldValueChanged(FieldId);
	return true;
}
MVVMViewModelBase.h(84): [C2678] binary '==': no operator found which takes a left-hand operand of type 'T' (or there is no acceptable conversion)

Does the UE_MVVM_SET_PROPERTY_VALUE macro not support TMap types? Is there a fix for this issue?

The error you’re seeing is because the TMap type does not have a == operator defined for it, which is used in the SetPropertyValue function template to check whether the new value is equal to the old value.

To fix this issue, you can modify the SetPropertyValue function template to use the != operator instead of == operator, or you can define an == operator for the TMap type.

1 Like

I ran into the same error trying to modify SetPropertyValue, as I didn’t have a != operator overload either.

I solved this by creating a wrapper struct and overloading the == operator. Here’s my solution:

FORCEINLINE bool operator==(const FParamMap &Other) const { return Name.IsEqual(Other.Name) && Map.Num() == Other.Map.Num(); }
1 Like