Table of Contents

Class StorageInstance

Namespace
S1API.Storages
Assembly
S1API.dll

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

StorageAccessSettings

IsOpened

Whether this storage container is currently opened by a player.

public bool IsOpened { get; }

Property Value

bool

ItemCount

The current number of items stored in this storage container.

public int ItemCount { get; }

Property Value

int

Name

The display name of this storage container.

public string Name { get; }

Property Value

string

SlotCount

The total number of slots available in this storage container.

public int SlotCount { get; }

Property Value

int

Slots

An array of all slots available on the storage container.

public ItemSlotInstance[] Slots { get; }

Property Value

ItemSlotInstance[]

Subtitle

The subtitle of this storage container.

public string Subtitle { get; }

Property Value

string

Methods

AddItem(ItemInstance)

Adds an item instance to this storage container.

public void AddItem(ItemInstance itemInstance)

Parameters

itemInstance ItemInstance

The 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

itemInstance ItemInstance

The item instance you want to store.

quantity int

The 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

gameObject GameObject

The 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

gameObject GameObject

The 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

itemDefinitionId string

The 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

itemInstance ItemInstance

The 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

itemDefinitionId string

The ID of the item definition to remove.

quantity int

The 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

Action

OnContentsChanged

An action fired when the contents of the storage container change (items added or removed).

public event Action OnContentsChanged

Event Type

Action

OnOpened

An action fired when the storage container is opened by the player.

public event Action OnOpened

Event Type

Action