How to use a PrimaryDataAsset as a key in a TMap?

I have a TMap in a GameInstanceSubsystem, and I’m trying to use a PrimaryDataAsset as the key. UCommonViewData is just a blank PrimaryDataAsset for now.

TMap<UCommonViewData, TWeakObjectPtr<UCommonActivatableWidget>> DataToInstanceMap;

When I try to compile, I get:

Error C2665 : 'GetTypeHash': no overloaded function could convert all the argument types

How can I resolve this? Should I use a pointer for the key? I just want to make sure that there is only one entry for each UCommonViewData that is created in the project.

I asked around, and I found a solution that worked for me. The solution is to avoid using a hard reference to the object and also to avoid using pointers, but instead use a FObjectKey.

For example, my TMap is now:

TMap<FObjectKey, TWeakObjectPtr<UCommonActivatableWidget>> DataToInstanceMap;

And I can get an FObjectKey by…

bool UCommonViewSubsystem::AddInstance(UCommonViewData* Key, UCommonActivatableWidget* UI)
{
	FObjectKey ObjectKey(Key); // This runs the constructor of FObjectKey using a pointer
    if (DataToInstanceMap.Contains(ObjectKey))
	{
        //...

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.