s&box
RustCounter-Strike 2s&boxDeadlock
Wiki
Get s&box on Steam
Browse
OverviewGetting StartedCreating GamesEngine & ToolsDocumentationCommunity GamesResources
s&boxDocumentationGameplayInventory WeaponsInventory
SOURCE 2 · C#
Build and play games with s&box.

Facepunch's game engine and creation platform — make games in C#, or jump straight into community games.

Get s&box on Steam

s&box Wiki

  • Overview
  • Getting Started
  • Creating Games
  • Engine & Tools
  • Documentation
  • Community Games
  • Resources

Tools & Community

  • Getting Started
  • Creating Games
  • Engine & Tools
  • Resources

Platforms

  • RustBattle
  • CSBattle
  • Rust Game Wiki
  • CS2 Skins Wiki
  • Deadlock Wiki

About

  • Official Site
  • Developer Wiki
  • GitHub
  • Get on Steam
NOT AFFILIATED WITH FACEPUNCH STUDIOS · © 2026 s&box Wiki (community)
Docs/Gameplay
Gameplay

Inventory

Add a BaseInventoryComponent to your player and it can carry things. It keeps items in slots, remembers which one is deployed, and handles picking up, dropping and switching.

Slots

MaxSlots sets how many slots there are, and Behaviour sets how they work:

BehaviourDescription
HotbarOne item per slot, like Rust or Minecraft. When an item's preferred slot is taken it goes to the first empty one.
BucketsSlots are categories and any number of items share one, like GMod or Half-Life. Items always land in their preferred slot.

Items ask for a slot with their PreferredSlot property, and sort within a bucket by SlotOrder.

Picking things up

PickupMode controls how the inventory takes items lying in the world:

ModeDescription
NoneIt doesn't. Call PickupWorldItem from your own code when you want one taken.
TouchWalking near a world item picks it up, like GMod or Quake.
UseThe player presses use on the item to take it.

With AutoSwitchOnPickup on, picking up something better than what's held deploys it. Better means a higher Value, which you set on each item.

Picking up a weapon the player already has doesn't give a second copy. The duplicate donates its ammo to the reserve instead.

Loadouts

Turn the Loadout feature on to have starting gear. StartingItems is a list of prefabs given when the inventory starts, along with any StartingAmmo. Call GiveLoadout() yourself when you want to give it again, on respawn for example.

Switching, dropping, removing

Switch( item ) deploys an item, Drop( item ) throws it out into the world, Remove( item ) destroys it. Query what's held with Items, ActiveItem, GetSlot( n ) and GetItem<T>().

var inventory = player.GetComponent<BaseInventoryComponent>();
var item = inventory.ActiveItem;

if ( item.IsValid() )
	Log.Info( $"Holding {item.DisplayName} in slot {item.Slot}" );

All of this is host authoritative. The owning client can call these too, they route through the host.

Ammo

Reserve ammo lives on the inventory, not on the weapon, so two guns that share an ammo type share their reserve. An ammo type is a BaseAmmoResource asset with a name, an icon and a max reserve. Create one from the Asset Browser.

GetAmmo, GiveAmmo and TakeAmmo on the inventory read and change the pool.

Making an item

BaseInventoryItem is anything an inventory can hold. On its own it's a pickup with a display name, an icon and a slot preference. Override its hooks to give it behaviour:

  • OnEquipped / OnHolstered run on every peer when it's deployed or put away.
  • OnControl runs each frame on the owning client while it's deployed. Read input here.
  • OnAdded / OnRemoved run on the host when it enters or leaves an inventory.
  • OnDrop places the item in the world when dropped. Return false to refuse the drop.

:::info There's no built in inventory or hotbar UI. Build your own from Items, GetSlot and ActiveItem. They're synced and cheap enough to read from HUD code every frame. :::

Source: Facepunch/sbox-docs (CC-BY-4.0) · updated 2026-07-04. Read it rendered on the official docs.

More in Gameplay

Clutter
Controller Input
Costs & Filters
Creating Terrain
Gameplay
Glyphs
Input
Inventory & Weapons
← All documentation

Community wiki — not affiliated with Facepunch Studios. For the latest and most authoritative information, see the official developer wiki.