Class StorageInstance
Represents a storage container in-game.
public class StorageInstance
- Inheritance
-
StorageInstance
- Inherited Members
- Extension Methods
Remarks
This is the user-facing layer for interacting with an existing storage instance: reading metadata (name, subtitle, slots/items), checking fit, adding/removing items, and subscribing to open/close/content-change events. It intentionally does not mutate slot topology or placeable wiring; use StorageEntity for capacity and structural changes.
Properties
AccessSettings
The access settings for this storage container.
public StorageAccessSettings AccessSettings { get; set; }
Property Value
IsOpened
Whether this storage container is currently opened by a player.
public bool IsOpened { get; }
Property Value
ItemCount
The current number of items stored in this storage container.
public int ItemCount { get; }
Property Value
Name
The display name of this storage container.
public string Name { get; }
Property Value
SlotCount
The total number of slots available in this storage container.
public int SlotCount { get; }
Property Value
Slots
An array of all slots available on the storage container.
public ItemSlotInstance[] Slots { get; }
Property Value
Subtitle
The subtitle of this storage container.
public string Subtitle { get; }
Property Value
Methods
AddItem(ItemInstance)
Adds an item instance to this storage container.
public void AddItem(ItemInstance itemInstance)
Parameters
itemInstanceItemInstanceThe item instance you want to store.
CanItemFit(ItemInstance, int)
Whether an item can fit inside this storage container or not.
public bool CanItemFit(ItemInstance itemInstance, int quantity = 1)
Parameters
itemInstanceItemInstanceThe item instance you want to store.
quantityintThe quantity of item you want to store.
Returns
- bool
Whether the item will fit or not.
FromGameObject(GameObject)
Gets a storage instance from a GameObject that has a StorageEntity component.
public static StorageInstance? FromGameObject(GameObject gameObject)
Parameters
gameObjectGameObjectThe GameObject to check for a StorageEntity component.
Returns
- StorageInstance
A StorageInstance wrapper if found, otherwise null.
Remarks
This method first checks the GameObject itself, then searches up the parent hierarchy. Useful for getting storage from spawned prefabs like Display Cabinets, Wall Shelves, etc.
FromGameObjectInChildren(GameObject)
Gets a storage instance from a GameObject that has a StorageEntity component in its children.
public static StorageInstance? FromGameObjectInChildren(GameObject gameObject)
Parameters
gameObjectGameObjectThe GameObject to search.
Returns
- StorageInstance
A StorageInstance wrapper if found, otherwise null.
Remarks
This method searches the GameObject and all its children for a StorageEntity component. Use this when the storage component might be on a child object.
GetContentsDictionary()
Gets a dictionary mapping item instances to their quantities in this storage container.
public Dictionary<ItemInstance, int> GetContentsDictionary()
Returns
- Dictionary<ItemInstance, int>
A dictionary where keys are item instances and values are quantities.
GetItems()
Gets all item instances currently stored in this storage container.
public ItemInstance[] GetItems()
Returns
- ItemInstance[]
An array of item instances.
RemoveAllOfDefinition(string)
Removes all items matching the given item definition ID from this storage container. This performs a soft removal (decrements quantity) and does not spawn world items.
public int RemoveAllOfDefinition(string itemDefinitionId)
Parameters
itemDefinitionIdstringThe ID of the item definition to remove.
Returns
- int
The total quantity that was removed.
RemoveItem(ItemInstance)
Removes a specific item instance from this storage container. This performs a soft removal (decrements quantity) and does not spawn world items.
public int RemoveItem(ItemInstance itemInstance)
Parameters
itemInstanceItemInstanceThe item instance to remove.
Returns
- int
The quantity that was removed.
TryRemoveQuantity(string, int)
Attempts to remove a specific quantity of items matching the given item definition ID. This performs a soft removal (decrements quantity) and does not spawn world items.
public int TryRemoveQuantity(string itemDefinitionId, int quantity)
Parameters
itemDefinitionIdstringThe ID of the item definition to remove.
quantityintThe quantity to remove.
Returns
- int
The actual quantity that was removed (may be less than requested if insufficient items exist).
Events
OnClosed
An action fired when the storage container is closed by the player.
public event Action OnClosed
Event Type
OnContentsChanged
An action fired when the contents of the storage container change (items added or removed).
public event Action OnContentsChanged
Event Type
OnOpened
An action fired when the storage container is opened by the player.
public event Action OnOpened