Question regarding removing a struct from TArray

Hello. I’m trying to make a simple Container Component, that holds a TArray of items. The items are a struct - FItemInstance. There’s a function for removing items, that calls Remove on the TArray with a const & to an item (assuming the array contains it). However, using the Remove throws a whole bunch of errors, with (I think) most relevant being:

BRWContainerComponent.cpp(46): note: see reference to function template instantiation 'int TArray<FItemInstance,FDefaultAllocator>::Remove(const FItemInstance &)' being compiled

Here’s the TArray and function from .h:

UPROPERTY(VisibleAnywhere)
	TArray<FItemInstance> StoredItems;

UFUNCTION(BlueprintCallable)
	void RemoveItem(const FItemInstance& ItemInstance);

and here’s the function in .cpp:

void UBRWContainerComponent::RemoveItem(const FItemInstance& ItemInstance)
{
	if (StoredItems.Contains(ItemInstance))
	{		
		StoredItems.Remove(ItemInstance);
	}
}

I’ve tried removing both UPROPERTY() and UFUNCTION() and it didn’t help. Any ideas what I’m doing wrong? My VS (with VA) doesn’t even highlight any errors…

I also don’t understand why only Remove() is wrong, since Contains() has the same definition and is used in the same way. EDIT: nvm it does. If I comment out Remove it breaks on Contains…

Thx to help from elsewhere I know it’s caused by my struct not having == operator defined. I would probably use UObject here instead of a struct (though unique id property for the struct was also propsed and it would work too)

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