Skip to content
Pablo Rodriguez

Inventory System

Create comprehensive structure for all loot items:

  • ID String: Unique identifier for item type (used for stacking)
  • Name Text: Display name in UI
  • Appearance_3D Static Mesh: 3D world representation
  • UI Texture System: Background, icon, and border textures with color options
// Loot UI Representation System
Struct_Loot {
Texture_Background: Texture2D;
Texture_Icon: Texture2D;
Texture_Border: Texture2D;
Texture_Background_Color: LinearColor;
Texture_Icon_Color: LinearColor;
Texture_Border_Color: LinearColor;
}

Create item database using data tables:

  • DT_Loot_Example: Template data table structure
  • Unique IDs: Each item needs distinct ID for proper stacking
  • Default Values: Set reasonable defaults for texture and color systems

Create base loot actor with data table integration:

  • Arrow Component: Root for positioning control
  • Static Mesh Component: 3D appearance
  • Box Collision: Interaction detection
  • Rotating Movement: Visual appeal
// Loot Actor Data Integration
OnConstruction() {
loot_data = GetDataTableRow(DataTable_Loot, 'NewRow');
StaticMesh_Appearance.SetStaticMesh(loot_data.Appearance_3D);
// Apply scale and positioning based on mesh
}

Connect loot to inventory system:

  • Interact Event: Add loot to player inventory
  • Destroy Actor: Remove loot from world after pickup
  • Interface Integration: Use Interface_Inventory_Add function

Create inventory storage system:

  • Inventory Array: Struct_Loot array for item data
  • Inventory_Quantity Array: Integer array for item quantities
  • Array Synchronization: Both arrays must maintain identical indices

Handle adding items to inventory with stacking:

// Inventory Add Implementation
Interface_Inventory_Add(Loot) {
if (Inventory.Contains(Loot)) {
// Item exists - increase quantity
item_index = Inventory.Find(Loot);
current_quantity = Inventory_Quantity[item_index];
Inventory_Quantity[item_index] = current_quantity + 1;
} else {
// New item - add to inventory
Inventory.Add(Loot);
Inventory_Quantity.Add(1);
}
UpdateInventoryWidget();
}

Handle removing items with validation:

Validate sufficient resources before removal:

// Inventory Validation
F_Check_Inventory(RequiredItems[], RequiredQuantities[]) -> Bool {
ForEach(item in RequiredItems) {
if (!Inventory.Contains(item)) {
F_Player_Error('Not enough ' + item.Name);
return false;
}
item_index = Inventory.Find(item);
current_amount = Inventory_Quantity[item_index];
required_amount = RequiredQuantities[index];
if (current_amount < required_amount) {
F_Player_Error('Not enough ' + item.Name);
return false;
}
}
return true; // All items available
}

Remove items only after validation passes:

  • Validation First: Use F_Check_Inventory before any removal
  • Quantity Reduction: Subtract required amounts from inventory quantities
  • UI Update: Refresh inventory display after changes

Create scrollable inventory interface:

  • Size Box Root: 400x800 container
  • Scroll Box: Vertical scrolling for large inventories
  • Vertical Box: Container for inventory items
  • Background Image: Visual styling for inventory panel

Individual item display component:

  • Icon Template: Reuse existing icon system
  • Text Blocks: Item name and quantity display
  • Layout: Icon on left, name in center, quantity on right
  • Scaling: 0.45 scale for appropriate sizing
// Inventory Update System
Interface_Widget_Inventory_Update(InventoryArray, QuantityArray) {
VerticalBox.ClearChildren(); // Clear existing items
ForEach(item in InventoryArray) {
item_widget = CreateWidget(W_Inventory_Item);
item_widget.SetLootData(item, QuantityArray[index]);
VerticalBox.AddChild(item_widget);
}
}

Add inventory to main UI system:

  • Size to Content: Enable for proper sizing
  • Anchor: Middle right positioning
  • Default Visibility: Hidden until opened
  • Toggle System: B key to open/close inventory

Follow standard widget integration pattern:

  • HUD Interface: Get_Widget_Inventory function
  • Widget Variable: Widget_Inventory reference in player character
  • Toggle Function: Interface_Widget_Inventory_Toggle for show/hide

Set up test environment:

  • Multiple Loot Types: Create various data tables for different items
  • Child Loot Actors: Specialized loot actors for different item types
  • Quantity Testing: Verify stacking works correctly
  • UI Testing: Confirm inventory display updates properly

The inventory system provides essential item management functionality while maintaining clean, extensible architecture for future crafting, trading, and progression systems.