Quick answer: Use a key field. Find by predicate matching the key. Add only when not found.
Inventory uses an FInventoryItem struct with ItemID + Quantity. Add Unique with same ID but different Quantity adds again because Quantity differs.
The Fix
// BP function: AddOrUpdateInventory
Inputs: Items (Array of FInventoryItem ref), New (FInventoryItem)
For each Item in Items:
Branch: Item.ItemID == New.ItemID
True → Set Item.Quantity = Item.Quantity + New.Quantity; return
Add(Items, New) // truly new ID
De-dup logic lives in your function. Add Unique BP node only handles primitives; structs need explicit key handling.
C++ Native Compare
USTRUCT(BlueprintType)
struct FInventoryItem {
GENERATED_BODY()
UPROPERTY(EditAnywhere) FName ItemID;
UPROPERTY(EditAnywhere) int32 Quantity;
bool operator==(const FInventoryItem& o) const {
return ItemID == o.ItemID; // key only
}
};
Verifying
Add same ItemID twice with different quantities: list keeps one entry, quantity sums. Different ItemID: separate entry.
“Key on identity. De-dup explicitly. Inventory clean.”
Related Issues
For BP Interface defaults, see BP Interface. For replication scope, see replication.
Identity key. Find then add.