Skip to content

📏 Policies

Defines per-container default sizes through the ContainerSizePolicy asset.
Used by SceneInventoryService when lazily creating containers that do not yet exist.

🎒 Ideal for setting backpack / hotbar / chest defaults
🧩 Optional — if missing, the service falls back to internal rules


Purpose

Provides a central, authorable place to define initial container sizes per container name
(e.g. "Backpack", "Hotbar", "ChestA").

This keeps capacity rules: - Out of code - In one ScriptableObject - Easy to audit and adjust


🚀 Quick Start

  1. CreateRevFramework → Inventory → Container Size Policy
  2. Edit the entries:
new Entry { name = "Backpack", size = 24 }
new Entry { name = "Hotbar",   size = 8  }
  1. Assign the asset to your SceneInventoryService.

Runtime Behaviour

🔍 Matching Rules

When a container is first created:

  • Container names are canonicalised (Trim().ToLowerInvariant())
  • Matching is case-insensitive
  • First match wins

If no policy entry matches:

  • "Backpack" → falls back to CharacterInventory.backpackSize (default 24)
  • All other containers → fall back to 12 slots

🎒 Backpack Special Case

Backpack sizing supports two layers:

  1. CharacterInventory.backpackSize
  2. ContainerSizePolicy (when allowed)

Controlled by:

SceneInventoryService.policyOverridesBackpack

Behaviour

  • OFF (default)
    → Backpack always uses CharacterInventory.backpackSize

  • ON
    → If the policy contains a "Backpack" entry, it overrides the CharacterInventory size
    → If the policy does not contain a Backpack entry, the CharacterInventory size is used

This ensures the policy only overrides backpack sizing when explicitly configured.


🏗️ Example

[SerializeField] private ContainerSizePolicy sizePolicy;

void Awake()
{
    SceneInventoryService.Instance.sizePolicy = sizePolicy;
}

When a container named "Hotbar" is created and exists in the policy,
its size is taken directly from the policy entry.


⚠️ Notes & Gotchas

  • Policies apply only at container creation time
  • Changing the policy does not resize existing containers
  • Resizing existing containers must be done explicitly via:
SceneInventoryService.ResizeContainer(...)
  • Invalid or zero sizes are clamped to ≥ 1

  • Data → item and slot definitions
  • Services → how policies are applied during container creation
  • CharacterbackpackSize vs policyOverridesBackpack