ItemStruct Error

I’ve finally finished my inventory system but for some reason can’t get past this error:
binary ‘==’: no operator found which takes a left-hand operand of type 'const FInventorySlotStruct(or there is no acceptable conversion). Occurs in Array.h line 952.

Currently using:

for (FInventorySlotStruct Content : InventoryContent)
	{
		if (Content.ItemID == ItemID)
		{
		}
	}

and

for (FInventorySlotStruct Content : InventoryContent)
	{
		if (Content.Quantity == 0)
		{
		}
	}

Any reasons for this error?
FInventorySlotStruct is a custom c++ struct and InventoryContent derives from that struct.
Would appreciate any responses.:slight_smile:
Thanks in advance.

Never mind turns out I was looking at the wrong section of my code the section that gives this error is:

int Index = InventoryContent.Find(Content);

Any reasons for this?

could the passed Content be a nullptr causing an error?
try adding

int Index = -1;
if(Content != nullptr){
Index = InventoryContent.Find(Content);
}

also InventoryContent has to be valid

Sorry I provided the wrong information.
Here’s all the code:

bool UInventorySystemComponent::FindEmptySlot(int& Index)
{
	for (FInventorySlotStruct Content : InventoryContent)
	{
		if (Content.Quantity == 0)
		{
			Index = InventoryContent.Find(Content);
			return true;
		}
	}

	Index = -1;
	return false;
}

You can skip the find

bool UInventorySystemComponent::FindEmptySlot(int& Index)
{
int currentIndex = 0;
	for (FInventorySlotStruct Content : InventoryContent)
	{
		if (Content.Quantity == 0)
		{
			Index = currentIndex;
			return true;
		}
       currentIndex++;
	}

	Index = -1;
	return false;
}

But is there any particular reason this is happening? That’s the only thing I want to solve.

You may need to override the == operator just like in most programming languages (there its usually just called equals)

The system probably can’t define which properties are essential for the comparison.

Found this

I see tysm tho.:slight_smile:

Last question cause this occurs also in another part of my code which is here and I don’t know an equivalent replacement or a fix:

if (InventoryContent.Find(Content))
{
	return true;
}

You can use either the Hash implementation or override the == operator inside of the struct

bool operator==(const FMyStruct& Other) const;
	{
		return PropertyField == Other.PropertyField && Field == Field;
	}

of course replace FMyStruct with your struct name and compare the most unique property fields (like item name or extra prefixes / suffixes etc)

Again ty for all your help.:slight_smile:

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