Ivan3z
(Ivan3z)
May 9, 2023, 11:55am
1
This function works on Bluprint.
This function fails in C++ (compilation error).
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!!
Bojann
(Bojan)
May 9, 2023, 12:32pm
2
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;
}
Bojann
(Bojan)
May 9, 2023, 12:43pm
3
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
Ivan3z
(Ivan3z)
May 9, 2023, 12:49pm
4
It is perfect:
I think this is going to work. (at least it compiles without errors)
Thank you very much for your help!!
I am very grateful.
Bojann
(Bojan)
May 9, 2023, 12:53pm
5
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
1 Like