AddUnique to TArray of Structures causes error

When using AddUnique to add a new structure to a TArray of structures, VisualStudio returns this error:

Error	C2678	binary '==': no operator found which takes a left-hand operand of type 'const FWeaponState' (or there is no acceptable conversion)

This is my structure setup:

USTRUCT(BlueprintType)
struct FWeaponState
{
	GENERATED_BODY()
	EWeaponState state;
	int32 priority;
	FTimerHandle* state_timer;
	bool bInfinite;
	bool bDestroyIfInactive;
};

The function that causes the error when trying to compile (StateBuffer is the TArray):

StateBuffer.AddUnique(new_state);

I’m unsure if this is intended/expected or just a limitation, but I’m posting this here because I couldn’t find any info about it online.

Amusingly enough, I’ve never needed to compare structs this way in C++ before. You can’t ‘==’ compare structs normally in C++, and that appears to be how AddUnique works, with no special changes made to make structs work with the function.

So, one has to write their own comparison function if they had wanted to do an AddUnique with structures.

1 Like