CharacterInventory
Character component that manages item slot selection, item spawning/despawning, and carry interactions for a character's hotbar-style inventory.
Definition
Namespace: Paragon.Townskeep.CharacterSystem
Assembly: Townskeep.dll
[Serializable]
public class CharacterInventory : CharacterComponentInheritance: ParagonComponent<Character> → CharacterComponent → CharacterInventory
Remarks
CharacterInventory bridges the Inventory data system with the character's physical world. It manages a hotbar/toolbar paradigm where:
The character has an
Inventorywith multiple slots.One slot is active at a time (
CurrentIndex).Switching slots physically despawns the current item and spawns the new one.
Spawned items are automatically picked up via
CarryInteractionthrough the character'sInteractor.
The slot-switching logic handles the full lifecycle: cancel current carry interaction → despawn current item → update index → spawn new item at character position → initiate carry interaction.
Quick Lookup
Get current slot data
characterInventory.GetCurrentSlot()
Set item in current slot
characterInventory.SetCurrentSlot(item, amount)
Clear current slot
characterInventory.ClearCurrentSlot()
Cycle to next slot
characterInventory.SwitchNextSlot()
Cycle to previous slot
characterInventory.SwitchPreviousSlot()
Jump to specific slot
characterInventory.SwitchToSlot(index)
Access underlying inventory
characterInventory.Inventory
Get held item reference
characterInventory.CurrentItem
Properties
Inventory
The underlying Inventory data container.
CurrentItem
The currently spawned Item in the world (the physical representation of the active slot). null if the active slot is empty.
CurrentIndex
The index of the currently active slot.
Events
CurrentSelectionChanged
Fires when the active slot index changes.
index
int
The new active slot index
Methods
SetCurrentSlot
Sets the item and amount in the currently active slot.
item
Item
The item to place in the slot
amount
int
Stack count (default: 1)
GetCurrentSlot
Returns the InventorySlot data for the currently active slot.
ClearCurrentSlot
Clears the current slot and nullifies the CurrentItem reference.
SwitchNextSlot
Cycles to the next slot (wraps around).
SwitchPreviousSlot
Cycles to the previous slot (wraps around).
SwitchToSlot
Switches to a specific slot index. Handles the full despawn → spawn → carry lifecycle.
index
int
Target slot index
Slot switch flow:
If holding an item with an active
CarryInteraction, cancel the interaction (without despawn animation) and despawn the item.Update
currentIndexand fireCurrentSelectionChanged.If the new slot has a valid
ItemID, spawn the item viaItemSpawner, position it at the character, sync physics, and start aCarryInteraction.
Lifecycle
OnInitialize()
Caches CharacterInteractor reference, sets index to 0, initializes the Inventory
Common Pitfalls
SwitchToSlot spawns network items — ItemSpawner.Spawn() creates a networked item with the character's OwnerClientId. This must be called from a network-authorized context.
Physics.SyncTransforms is called during switch — Slot switching forces a physics sync to ensure the spawned item is at the correct position before the carry interaction begins.
SetCurrentSlot does not trigger slot switching — It only updates the slot data. To physically swap the held item, call SwitchToSlot() after modifying slot data.
See Also
CharacterInteractor — provides the
Interactorused for carry interactions
Last updated