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.
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?
3dRaven
(3dRaven)
July 1, 2023, 8:35am
3
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;
}
3dRaven
(3dRaven)
July 1, 2023, 8:42am
5
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.
3dRaven
(3dRaven)
July 1, 2023, 8:46am
7
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
This is a really old post but just in case anyone else comes across this issue. You need to implement GetTypeHash inside your struct.
With the above example you’d probably want something like this:
friend uint32 GetTypeHash(const FSaveStruct& other)
{
return GetTypeHash(other.ObjectUUID.ToString() + other.UserUUID);
}
This works really well with this struct example because this function should return something that makes this struct unique to all others. If you don’t have something like a…
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;
}
3dRaven
(3dRaven)
July 1, 2023, 9:01am
10
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.
system
(system)
Closed
July 31, 2023, 9:05am
12
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.