I am trying to create an inventory based system using two USTRUCTS FAlchemyItem (FAI) and FAlchemyFluid (FAF). The FAlchemyItem contains and FAlchemyFluid and is generally used as a transporter for the FAF as multiple different FAI’s can have the same FAF.
The inventory is a TArray. There is a Find() in the processor when attempting to add the ‘item’ to the inventory.
Error Log:
Array.h(886): error C2678: binary ‘==’: no operator found which takes a left-hand operand of type ‘const FAlchemyFluid’ (or there is no acceptable conversion)
.
Array.h(886): note: while trying to match the argument list '(const FAlchemyFluid, FAlchemyFluid *const )
.
GameplayController.cpp(39): note: see reference to function template instantiation 'int32
.
TArray::IndexOfByKey(const KeyType &) const’ being compiled
with
[
KeyType=FAlchemyFluid *
]
(Appologies for the ‘.’ I’m using them to keep the error log neat.)
I have tried multiple different ways of overloading the operator and have to no avail been able to solve this. At this point I have no idea what the error even is. Could id be that the comparision is trying to compare to a nullptr?
FAlchemyFluid Definition:
USTRUCT(BlueprintType)
struct FAlchemyFluid : public FTableRowBase {
GENERATED_BODY()
public:
// Unique Fluid ID
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FName FluidID;
bool operator==(const FAlchemyFluid &other) const {
if (FluidID == other.FluidID) { return true; }
else { return false; }
}
};
FluidInventory Definition:
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
TArray<FAlchemyFluid> FluidInventory;
Use of the Find():
void AGameplayController::AddItemToInventoryByID(FName ID) {
AGameplayGameMode *GameMode = Cast<AGameplayGameMode>(GetWorld()->GetAuthGameMode());
UDataTable *ItemTable = GameMode->GetItemDB();
UDataTable *FluidTable = GameMode->GetFluidDB();
const FAlchemyItem *ItemToAdd = ItemTable->FindRow<FAlchemyItem>(ID, "");
const FAlchemyFluid *FluidToAdd = FluidTable->FindRow<FAlchemyFluid>((ItemToAdd->Fluid.FluidID), "");
if (ItemToAdd) {
if (FluidToAdd) {
//Checks to see if fluid is in inventory already and increments it by item value
int32 i;
if (FluidInventory.Find(*FluidToAdd, i)) {
FAlchemyFluid *ExistingFluid = FluidInventory.FindByKey(ItemToAdd->Fluid);
FluidInventory[FluidInventory.IndexOfByKey(ExistingFluid)].Volume += ItemToAdd->Value;
}
else { FluidInventory.Add(*FluidToAdd); }
}
}
}
Please let me know if I didn’t provide enough information. I will respond ASAP.
Thank you for your help