Why TArray works in Blueprint and fails in C++?

This function works on Bluprint.

This function fails in C++ (compilation error).
7

The structure is exactly the same in Blueprint and in C++.

It seems that the compiler can’t find a comparison operator.

Is something missing in the C++ function?

Do we have to implement the == operator in the PlayerProfiler structure?

Or what is really the problem?

Thank you so much!!

I just tried your exact implementation on my game and it worked for me

bool UFragileGameInstance::FindMyIndex(FString& ProfileInfo)
{
	int32 FoundIndex = CampaignAvailableNames.Find(ProfileInfo);
	if (FoundIndex == INDEX_NONE) return false;
	return true;
}

You can make it even more simple like this:

bool UCSaveGame::PlayerInfoExist(const FPlayerProfile &IntProfile)
{
	return ProfileArray.Find(IntProfile) != INDEX_NONE;
}

Ah, sorry, my bad. Seems like you are trying to compare structs :).

You will have to do a bit of hacking there. Open your struct, add some comparator value, for example UniquePlayerInfoId.

Then in your struct create method:

bool operator==(const FPlayerProfile & Compared) const
{
	return Compared.UniquePlayerInfoId== UniquePlayerInfoId;
}

Here is the full code how it looks like in my struct, where I tested it.

USTRUCT(BlueprintType)
struct FUpgradeLevel : public FTableRowBase
{
	GENERATED_USTRUCT_BODY()

	int32 UniqueId;
	
	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Upgrade Level")
	int32 Min = 0;
	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Upgrade Level")
	int32 Max = 0;
	bool operator==(const FUpgradeLevel& Type) const
	{
		return Type.UniqueId == UniqueId;
	}
};

Bad news is, you will have to handle UniquePlayerId somehow.

1 Like

It is perfect:
I think this is going to work. (at least it compiles without errors)

ok

Thank you very much for your help!!
I am very grateful.

Just doublecheck if this works. Since you still compare two structs. I think you will have to go with some sort of identifier, like I have given in the example. But, if this work, even better :slight_smile:

1 Like