Skip to main content

Replication & Multiplayerr

Overview

InventoryComponent is fully replicated for multiplayer games.

Replicated Properties

  • Items array: All inventory slots
  • Max Slots: Capacity
  • Max Weight: Weight limit
  • Current Weight: Total weight

Server Authority

All inventory modifications go through the server:
  1. Client calls AddItem()
  2. Server validates and adds item
  3. Server replicates change to all clients
  4. Clients receive updated inventory

RPC Functions

Server RPCs for authority:

Client Prediction

For responsive gameplay, implement client-side prediction:

Best Practices

  1. Use AddItem() for simplicity: When you just need to add items by type
  2. Use AddItemInstance() for custom items: When items have unique properties
  3. Handle overflow: Always check for overflow when adding items
  4. Validate before removing: Check if items exist before removing
  5. Use events for UI updates: Bind to OnSlotUpdated for reactive UI
  6. Enable auto-sort for convenience: Makes inventory management easier
  7. Set appropriate weight limits: Balance realism with gameplay
  8. Test multiplayer: Ensure all operations work with server authority
  9. Use container restrictions: Prevent players from breaking game logic
  10. Implement weight penalties: Make encumbrance meaningful

Common Patterns

Safe Item Addition

Transferring with Validation

Consuming Ingredients


Performance Considerations

  • Slot count: More slots = more memory and replication cost
  • Weight calculations: Cached and updated on changes only
  • Sorting: O(n log n) operation - don’t sort every frame
  • Replication: Only changed slots replicate (not entire inventory)
  • UI updates: Use events to update only changed slots