Unreal Engine 5 c++ GetValueTypeHash definition in TSet<customStruct>

I a trying to create a set of structs using TSet, however, when I compile I get the error:

The structure Fpiece is used in a TSet but does not have a GetValueTypeHash defined

How do I implement a GetValueTypeHash definition in my struct?

USTRUCT(BlueprintType)
struct Fpiece
{
    GENERATED_BODY()
        // Use UPROPERTY() to decorate member variables as they allow for easier integration with network replication as well as potential garbage collection processing
    UPROPERTY(BlueprintReadOnly, Category = Tutorial) int color;
    UPROPERTY(BlueprintReadOnly, Category = Tutorial) int man;
    UPROPERTY(BlueprintReadOnly, Category = Tutorial) int locationX;
    UPROPERTY(BlueprintReadOnly, Category = Tutorial) int locationY;
    UPROPERTY(BlueprintReadOnly, Category = Tutorial) int point;

};

and in the public class definitions:

UPROPERTY(BlueprintReadOnly, Category = Tutorial) TSet<Fpiece> pieces;

1 Like

Add this in your header
image

and implement this like this
image

7 Likes

thanks. worked perfectly.

1 Like

You’re welcome, make sure you mark this as answered so others can find it easily.

1 Like

What’s the proper way to implement the operator== overload on the same struct?

inline bool operator ==(const Fpiece& other) const
    {
        return SomeData == other.SomeData;
    }

You can use any combination of member variables or just one. This type of overload goes inside of the UStruct.

1 Like

(post deleted by author)

(post deleted by author)