I also have trouble following the documentation page, it seem to target more advanced use-cases thus require the using the BaseKeyFuncs template.
What I needed is just a simple map however, and after some heavy Google-ing I at least got my TMap that uses a USTRUCT as key to compile, just by overriding the ==operator and GetTypeHash().
Note I only got it to compile and I still need more testing to check if everything is working ok.
Have you tried using GENERATED_USTRUCT_BODY() instead of GENERATED_BODY() for your struct? I know they “replaced” GENERATED_UCLASS_BODY() with GENERATED_BODY() but I’m not sure if the macro is meant to be used for USTRCTs too.
Off-topic: This is the one thing that I hate most for UE4, many things have been deprecated / changed since release but the internet is flooded with legacy use cases / information while there is not a central place that can verify what is currently correct. (there is the source-code but I think its not realistic for an average user to dig through it on every aspect…)
I tried using GENERATED_USTRUCT_BODY() , does not change anything.
FYI: GENERATED_UCLASS_BODY() doesn’t creates the constructor, GENERATED_BODY() does.
I never thought of going into the source code for something this simple, even when there is a documentation page.
So I did a search for TMap and found this great example.
Reflection system does not support TMap, so don’t place UPROPERTY(), you need to use USTRUCT() if you using structure as argument in function, because reflection system need to see structure in order for function argument to work in reflection system
I had the same problem and none of the answers here helped me really. I searched a while in the internet but couldn’t get something run for me so I looked in the unreal source code and I found out how I can solve my problem.
I searched for “uint32 GetTypeHash(” and the first header with it was AssetEditorSelectedItem.h from unreal source code. I found out that I had to write a function in my struct with a
uint32 GetTypeHash() const
{
// write your hash generation here
(I found some hash generation in FCrc.h if you need a hash generation)
}
body. Outside the USTUCT I had to implement a function with
FORCEINLINE uint32 GetTypeHash(const ‘structname’& other)
{
return other.GetTypeHash();
}
that’s for the hash, the function with
bool operator==(const ‘structname’& other) const
{
}
worked for me fine.
I know this post is really outdated but I hope my answer can help.
This works, too. And I understand it, because “TMap is similar to TSet in that its structure is based on hashing keys” therefore you need to somehow define the unique key value. However I found out that leaving the function basically blank will not provide you with the functionality needed, that means it will not consider two FStructs the same even those are the same. The workaround I found out is to define a simple rule to generate FString ID that is based on a combination of the most noticeable attributes of the FStruct (FName FirstName, FName LastName, for instance) and then matching the TMap key based on this FString ID. Creating new value for DominikPavlicek will show me the error because I have already defined this value.