Table of Contents

Class Container

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

Container interactable (chests, wardrobes, crates, etc.) that stores items and implements IItemContainer. Players can interact with it to view and take items. Configured via a ContainerTemplate ScriptableObject asset.

[RequireComponent(typeof(SceneObjectNamer))]
public class Container : Interactable, ISpawnable, IContainer, IInteractable, ISceneObject, IItemContainer
Inheritance
Object
Component
Behaviour
MonoBehaviour
NetworkBehaviour
Container
Implements
Inherited Members
NetworkBehaviour.IsSpawned
NetworkBehaviour.ComponentIndex
NetworkBehaviour.NetworkObject
NetworkBehaviour.MAXIMUM_NETWORKBEHAVIOURS
NetworkBehaviour.UNSET_NETWORKBEHAVIOUR_ID
NetworkBehaviour.ToString()
NetworkBehaviour.Reset()
NetworkBehaviour.OnValidate()
NetworkBehaviour.IsBehaviourReconciling
NetworkBehaviour.ClearReplicateCache()
NetworkBehaviour.CreateReconcile()
NetworkBehaviour.Reconcile_Reader<T>(PooledReader, ref T)
NetworkBehaviour.OnStartServerCalled
NetworkBehaviour.OnStartClientCalled
NetworkBehaviour.OnStartNetwork()
NetworkBehaviour.OnStopNetwork()
NetworkBehaviour.OnStopServer()
NetworkBehaviour.OnOwnershipServer(NetworkConnection)
NetworkBehaviour.OnSpawnServer(NetworkConnection)
NetworkBehaviour.OnDespawnServer(NetworkConnection)
NetworkBehaviour.OnStartClient()
NetworkBehaviour.OnStopClient()
NetworkBehaviour.OnOwnershipClient(NetworkConnection)
NetworkBehaviour.ClearBuffedRpcs()
NetworkBehaviour.ExcludeOwnerFromUnbufferedObserversRpcs
NetworkBehaviour.IsClientOnly
NetworkBehaviour.IsServerOnly
NetworkBehaviour.IsHost
NetworkBehaviour.IsClient
NetworkBehaviour.IsServer
NetworkBehaviour.IsDeinitializing
NetworkBehaviour.NetworkManager
NetworkBehaviour.ServerManager
NetworkBehaviour.ClientManager
NetworkBehaviour.ObserverManager
NetworkBehaviour.TransportManager
NetworkBehaviour.TimeManager
NetworkBehaviour.SceneManager
NetworkBehaviour.PredictionManager
NetworkBehaviour.RollbackManager
NetworkBehaviour.NetworkObserver
NetworkBehaviour.IsClientInitialized
NetworkBehaviour.IsClientStarted
NetworkBehaviour.IsClientOnlyInitialized
NetworkBehaviour.IsClientOnlyStarted
NetworkBehaviour.IsServerInitialized
NetworkBehaviour.IsServerStarted
NetworkBehaviour.IsServerOnlyInitialized
NetworkBehaviour.IsServerOnlyStarted
NetworkBehaviour.IsHostInitialized
NetworkBehaviour.IsHostStarted
NetworkBehaviour.IsOffline
NetworkBehaviour.IsNetworked
NetworkBehaviour.GetIsNetworked()
NetworkBehaviour.IsManagerReconciling
NetworkBehaviour.Observers
NetworkBehaviour.IsOwner
NetworkBehaviour.IsController
NetworkBehaviour.HasAuthority
NetworkBehaviour.Owner
NetworkBehaviour.OwnerId
NetworkBehaviour.ObjectId
NetworkBehaviour.LocalConnection
NetworkBehaviour.OwnerMatches(NetworkConnection)
NetworkBehaviour.Despawn(GameObject, DespawnType?)
NetworkBehaviour.Despawn(NetworkObject, DespawnType?)
NetworkBehaviour.Despawn(DespawnType?)
NetworkBehaviour.Spawn(GameObject, NetworkConnection, Scene)
NetworkBehaviour.Spawn(NetworkObject, NetworkConnection, Scene)
NetworkBehaviour.RemoveOwnership()
NetworkBehaviour.GiveOwnership(NetworkConnection)
NetworkBehaviour.GetInstance<T>()
NetworkBehaviour.TryRegisterInstance<T>(T)
NetworkBehaviour.UnregisterInstance<T>()
NetworkBehaviour.CanLog(LoggingType)
MonoBehaviour.IsInvoking()
MonoBehaviour.CancelInvoke()
MonoBehaviour.StopCoroutine(Coroutine)
MonoBehaviour.StopAllCoroutines()
MonoBehaviour.destroyCancellationToken
MonoBehaviour.useGUILayout
MonoBehaviour.didStart
MonoBehaviour.didAwake
MonoBehaviour.runInEditMode
Behaviour.enabled
Behaviour.isActiveAndEnabled
Component.GetComponent<T>()
Component.TryGetComponent<T>(out T)
Component.GetComponentInChildren<T>()
Component.GetComponentsInChildren<T>()
Component.GetComponentInParent<T>()
Component.GetComponentsInParent<T>()
Component.GetComponents<T>()
Component.GetComponentIndex()
Component.CompareTag(TagHandle)
Component.transform
Component.transformHandle
Component.gameObject
Component.tag
Object.GetEntityId()
Object.GetInstanceID()
Object.GetHashCode()
Object.InstantiateAsync<T>(T)
Object.InstantiateAsync<T>(T, Transform)
Object.InstantiateAsync<T>(T, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion, Transform)
Object.Instantiate(Object)
Object.Instantiate(Object, Scene)
Object.Instantiate<T>(T, InstantiateParameters)
Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
Object.Instantiate(Object, Transform)
Object.Instantiate<T>(T)
Object.Instantiate<T>(T, Vector3, Quaternion)
Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
Object.Instantiate<T>(T, Transform)
Object.Destroy(Object)
Object.DestroyImmediate(Object)
Object.DontDestroyOnLoad(Object)
Object.DestroyObject(Object)
Object.FindObjectsOfType<T>()
Object.FindObjectsByType<T>(FindObjectsSortMode)
Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
Object.FindObjectOfType<T>()
Object.FindFirstObjectByType<T>()
Object.FindAnyObjectByType<T>()
Object.FindFirstObjectByType<T>(FindObjectsInactive)
Object.FindAnyObjectByType<T>(FindObjectsInactive)
Object.FindObjectsByType<T>()
Object.FindObjectsByType<T>(FindObjectsInactive)
Object.name
Object.hideFlags

Fields

AchievementTemplate

Achievement to increment when a player opens this container.

public AchievementTemplate AchievementTemplate

Field Value

AchievementTemplate

Template

Template defining the container parameters.

public ContainerTemplate Template

Field Value

ContainerTemplate

Properties

Items

Gets the list of items contained in this container.

public List<Item> Items { get; }

Property Value

List<Item>

Title

The display title for this interactable, shown in the UI.

public override string Title { get; }

Property Value

string

TitleColor

The color of the title displayed for this interactable in the UI.

public override Color TitleColor { get; }

Property Value

Color

Methods

AddSlots(List<Item>, int)

Adds slots to the container, optionally initializing with a list of items.

public void AddSlots(List<Item> items, int amount)

Parameters

items List<Item>

The initial items to add (can be null).

amount int

The number of slots to add.

CanAddItem(Item)

Determines if the specified item can be added to the container.

public bool CanAddItem(Item item)

Parameters

item Item

The item to check.

Returns

bool

True if the item can be added, false otherwise.

CanInteract(IPlayerCharacter)

Returns true if the specified player character may interact with this object.

public override bool CanInteract(IPlayerCharacter character)

Parameters

character IPlayerCharacter

The player character attempting to interact.

Returns

bool

True if interaction is allowed, false otherwise.

Remarks

A pure question with no side effects. It used to stamp the character's interact rate-limit as part of answering, which made it unusable as a check: the scene server, the quest system and the client's input handler all call it, and each call silently consumed a limiter meant for one of the others. A quest accepted within the limiter's window of the interaction that opened the dialogue was refused by a debounce nobody intended to spend, and the refusal path sends nothing back — so the player saw a dead keypress. Spend the limiter explicitly with TryConsumeInteractRateLimit(IPlayerCharacter).

CanManipulate()

Determines if the container can be manipulated (e.g., items moved or swapped).

public bool CanManipulate()

Returns

bool

True if manipulation is allowed, false otherwise.

Clear()

Clears all items from the container.

public void Clear()

ContainsItem(BaseItemTemplate)

Checks if the container contains an item with the specified template.

public bool ContainsItem(BaseItemTemplate itemTemplate)

Parameters

itemTemplate BaseItemTemplate

The item template to search for.

Returns

bool

True if the item is found, false otherwise.

FilledSlots()

Gets the number of filled slots in the container.

public int FilledSlots()

Returns

int

The number of filled slots.

FreeSlots()

Gets the number of free slots in the container.

public int FreeSlots()

Returns

int

The number of free slots.

GetItemCount(BaseItemTemplate)

Gets the count of items matching the specified template.

public int GetItemCount(BaseItemTemplate itemTemplate)

Parameters

itemTemplate BaseItemTemplate

The item template to count.

Returns

int

The number of items matching the template.

HasFreeSlot()

Checks if the container has at least one free slot.

public bool HasFreeSlot()

Returns

bool

True if a free slot exists, false otherwise.

IsSlotEmpty(int)

Checks if the specified slot is empty.

public bool IsSlotEmpty(int slot)

Parameters

slot int

The slot index to check.

Returns

bool

True if the slot is empty, false otherwise.

IsSlotLocked(int)

Returns true if the specified slot is currently locked. Locked slots cannot be swapped, removed, or transferred until unlocked.

public bool IsSlotLocked(int slot)

Parameters

slot int

The slot index to check.

Returns

bool

True if the slot is locked, otherwise false.

IsValidSlot(int)

Checks if the specified slot index is valid for this container.

public bool IsValidSlot(int slot)

Parameters

slot int

The slot index to check.

Returns

bool

True if the slot is valid, false otherwise.

LockSlot(int)

Locks the specified slot, preventing it from being swapped, removed, or transferred.

public void LockSlot(int slot)

Parameters

slot int

The slot index to lock.

OnAwake()

Called when the object is awakened. Override to implement custom initialization logic.

public override void OnAwake()

OnStartServer()

Rolls this container's contents. Server only, once per spawn.

public override void OnStartServer()

Remarks

OnStartServer() rather than OnAwake, for the same reason NPC ability learning and scene object registration live there: Awake runs once per pooled instance, so a container respawned from the pool would come back with whatever its previous life left behind — which, since a looted chest ends empty, means empty forever. ResetState(bool) clears and re-sizes the slots on the way into the pool and this fills them on the way out.

The roll is server-side and the result reaches clients through WritePayload(NetworkConnection, Writer), which runs after this and before the spawn message is built. A client never rolls: it is told what is in the box.

ReadPayload(NetworkConnection, Reader)

Reads network payload data for this interactable, setting its ID and registering it in the scene.

public override void ReadPayload(NetworkConnection connection, Reader reader)

Parameters

connection NetworkConnection

The network connection.

reader Reader

The network reader.

RemoveItem(int)

Removes the item from the specified slot.

public Item RemoveItem(int slot)

Parameters

slot int

The slot index to remove the item from.

Returns

Item

The item that was removed, or null if no item was present.

ResetState(bool)

Rebuilds the slot list when this instance returns to the pool.

public override void ResetState(bool asServer)

Parameters

asServer bool

True when the reset is for the server instance.

Remarks

OnAwake() is what sizes the container, and Unity calls Awake once per instance rather than once per spawn — so a recycled container came back holding whatever its previous life had left in it, and a chest emptied by one player would respawn already empty for the next.

The slots are re-added rather than merely emptied, because a container whose template was assigned after Awake would otherwise come back with no slots at all.

SetItemSlot(Item, int)

Sets the item in the specified slot, refusing a locked slot. Callers must check the return value — see SetItemSlot(Item, int).

public bool SetItemSlot(Item item, int slot)

Parameters

item Item
slot int

Returns

bool

SwapItemSlots(int, int)

Swaps items between two slots.

public bool SwapItemSlots(int from, int to)

Parameters

from int

The source slot index.

to int

The destination slot index.

Returns

bool

True if the swap was successful, false otherwise.

SwapItemSlots(int, int, out Item, out Item)

Swaps items between two slots and returns the items that were swapped.

public bool SwapItemSlots(int from, int to, out Item fromItem, out Item toItem)

Parameters

from int

The source slot index.

to int

The destination slot index.

fromItem Item

The item originally in the source slot.

toItem Item

The item originally in the destination slot.

Returns

bool

True if the swap was successful, false otherwise.

TryAddItem(Item, out List<Item>)

Attempts to add the specified item to the container, returning a list of modified items.

public bool TryAddItem(Item item, out List<Item> modifiedItems)

Parameters

item Item

The item to add.

modifiedItems List<Item>

The list of items modified during the operation.

Returns

bool

True if the item was successfully added, false otherwise.

TryGetItem(int, out Item)

Attempts to get the item in the specified slot.

public bool TryGetItem(int slot, out Item item)

Parameters

slot int

The slot index to retrieve.

item Item

The item found in the slot, or null if not found.

Returns

bool

True if an item was found, false otherwise.

UnlockSlot(int)

Unlocks the specified slot, allowing normal manipulation again.

public void UnlockSlot(int slot)

Parameters

slot int

The slot index to unlock.

WritePayload(NetworkConnection, Writer)

Writes network payload data for this interactable, sending its ID to the writer.

public override void WritePayload(NetworkConnection connection, Writer writer)

Parameters

connection NetworkConnection

The network connection.

writer Writer

The network writer.

Events

OnSlotLockChanged

Event triggered when a slot's lock state changes. Parameters: container, slot index, isLocked.

public event Action<IItemContainer, int, bool> OnSlotLockChanged

Event Type

Action<IItemContainer, int, bool>

OnSlotUpdated

Event triggered when an item slot is updated (item added, removed, or changed).

public event Action<IItemContainer, Item, int> OnSlotUpdated

Event Type

Action<IItemContainer, Item, int>