Quick answer: Define operator== on the C++ struct. BP Array Find then works. Without ==, BP’s Find can’t compare struct values element-wise.
BP Array Find searches an FInventoryItem struct array for a matching item. Returns -1 even when the item is present. Struct equality is not defined.
The Symptom
Array Find with a struct argument always returns -1 except for very simple structs (single int field, sometimes).
The Fix
USTRUCT(BlueprintType)
struct FInventoryItem
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 Id;
UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 Count;
bool operator==(const FInventoryItem& Other) const
{
return Id == Other.Id; // match by Id only
}
};
Now BP Array Find compares by Id; matching elements are found.
BP-Only Workaround
Use ForEachLoop and break on a manual field comparison:
ForEachLoop(InventoryArray):
Element.Id == TargetId -> SET FoundIndex = ArrayIndex; Break
Verbose but works without C++ changes.
Verifying
Find an item that exists. Returns its index. Without ==: -1.
“Define equality. Find works.”
Related Issues
For Blueprint Interface cooked, see interface cast. For Blueprint async pending, see async task.
Equality defined. Searches work.