Back to search
PatternGold tierGameplay

Inventory: add/remove items with array of structs

Updated 3mo ago4 look-ups
UE 5.3UE 5.4UE 5.5UE 5.6UE 5.7#inventory#item#array#struct#add#remove

Reference

Create struct FInventoryItem: {ItemName (Name), ItemCount (int), ItemData (object ref)}.

Variable: Inventory (Array<FInventoryItem>).

AddItem: ForEachLoop(Inventory) → CastTo/Break FInventoryItem → Branch(ItemName==NewItem.Name) → True: Get → Modify Count → Array Set (replace at index) → return. If not found: Make FInventoryItem → Array Add.

RemoveItem: Find by name → Branch(Count>1) → True: decrement → Set at index. Else: Array Remove at index.

Key: Arrays of structs require 'Array Set' with index to modify in place — getting and modifying a copy does NOT update the array.