> For the complete documentation index, see [llms.txt](https://espergames.gitbook.io/inventool/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://espergames.gitbook.io/inventool/scripting/equipment.md). Agents can also search and read this documentation through its [MCP server](https://espergames.gitbook.io/inventool/~gitbook/mcp).

# Equipment

A class that gives a GameObject the ability to equip and unequip ItemStacks.

## Notes

* All properties visible in the component inspector can be accessed through code.

## Linking

You can link a [Character Stats](https://espergames.gitbook.io/inventool/scripting/character-stats.md) by setting the `linkedCharacterStats` field. This will apply all equipment stats to the character's stats.

You can link an [Inventory](https://espergames.gitbook.io/inventool/scripting/inventory.md) by setting the `linkedInventory` field. This will ensure all equipment slots only accept items from the linked inventory.

**Initialization is required for linking to work properly.**

## Initialize

Initialization sets up the equipment slots and apply any equipment that already exists on the linked character stats. This is usually handled automatically, but you can initialize manually by calling the `Initialize` method.

```csharp
myEquipment.Initialize();
```

Use `Uninitialize` to have the opposite effect (unset slots and equipment).

```csharp
myEquipment.Uninitialize();
```

## Slots

You can get the full list of slots with the `slots` field. Also see [Slot](https://espergames.gitbook.io/inventool/scripting/slot.md).

To get a specific slot by name, use the `GetSlot` method. You can also instead pass an [Item Stack](https://espergames.gitbook.io/inventool/scripting/items/item-stack.md) to get the slot that the item is contained in.

```csharp
var mySlot = myEquipment.GetSlot("My Slot");
```

## Equipment

Generally equipment handled automatically with slots, but you can also manage equipment manually.

### Equipping

Use the `TryEquip` method to equip an `ItemStack`. This may fail if the item cannot be equipped in any slot due to there not being a slot available that accepts the item.

```csharp
if (myEquipment.TryEquip(myItemStack, out Slot slotEquippedIn))
{
    Debug.Log($"Successfully equipped in the {slotEquippedIn.name} slot!");
}
```

To check if an item can be equipped, without actually equipping it, use the `CanEquip` method.

```csharp
if (myEquipment.CanEquip(myItemStack))
{
    // Do something...
}
```

To check if an item stack is equipped, use the `IsEquipped` method.

```csharp
if (myEquipment.IsEquipped(myItemStack))
{
    // Do something...
}
```

### Unequipping

To unequip an `ItemStack`, use the `TryUnequip` method. This will usually only fail if the item is not equipped.

```csharp
if (myEquipment.TryUnequip(myItemStack))
{
    Debug.Log("Successfully unequipped the item!");
}
```

### Get All Equipment

You can retrieve a list of all equipped items with the `GetAllItems` method.

```csharp
List<ItemStack> allEquippedItems = myEquipment.GetAllItems();
```

## Saving

See [Equipment](https://espergames.gitbook.io/inventool/scripting/saving-and-loading/equipment.md).

## Events

| Name         | Type                         | Description                                                                                                  |
| ------------ | ---------------------------- | ------------------------------------------------------------------------------------------------------------ |
| onEquipped   | UnityEvent\<Slot, ItemStack> | A callback for when an item is equipped. This accepts 2 arguments: the slot affected, the equipped item.     |
| onUnequipped | UnityEvent\<Slot, ItemStack> | A callback for when an item is unequipped. This accepts 2 arguments: the slot affected, the unequipped item. |
