# Item Type

## 🏷️ ItemType Class

A type of item. Item types are used to set commonalities of a group of items and are also useful for filtering items in the inventory.

> **Namespace:** `Esper.Inventool.Items`\
> **Access:** `public`\
> **Type:** `class`\
> **Inherits:** `InventoolObject`

***

### 📦 Fields

| Access   | Field                     | Type              | Description                                                                                   |
| -------- | ------------------------- | ----------------- | --------------------------------------------------------------------------------------------- |
| `public` | `displayName`             | `string`          | The display name of this type shown in‑game.                                                  |
| `public` | `localizedDisplayNameKey` | `string`          | The key of the localized display name string.                                                 |
| `public` | `icon`                    | `Sprite`          | The item type icon displayed in the inventory filter list.                                    |
| `public` | `iconColorTint`           | `Color`           | The color tint of the icon.                                                                   |
| `public` | `parent`                  | `ItemType`        | The parent item type. `null` if not a subtype.                                                |
| `public` | `enchantmentMode`         | `EnchantmentMode` | The enchantment mode of this item type.                                                       |
| `public` | `sortingOrder`            | `int`             | The order in which this type appears in the inventory filter list. Lower values appear first. |
| `public` | `equippable`              | `bool`            | If this item type supports equipping.                                                         |
| `public` | `consumable`              | `bool`            | If this item type supports consuming.                                                         |
| `public` | `stackable`               | `bool`            | If stacking is possible for items of this type.                                               |
| `public` | `droppable`               | `bool`            | If the player can manually drop items of this type.                                           |
| `public` | `sellable`                | `bool`            | If items of this type can be sold in marketplaces.                                            |

***

### 🔍 Properties

| Access   | Property        | Type   | Description                                       |
| -------- | --------------- | ------ | ------------------------------------------------- |
| `public` | `IsSubtype`     | `bool` | If this type is a subtype of another.             |
| `public` | `IsEnchantable` | `bool` | If items of this type can be enchanted.           |
| `public` | `IsEnchanter`   | `bool` | If items of this type can be used for enchanting. |

***

### 🧰 Methods

| Access          | Method                                           | Returns    | Description                                           |
| --------------- | ------------------------------------------------ | ---------- | ----------------------------------------------------- |
| `public`        | `GetLocalizedDisplayName()`                      | `string`   | Gets the localized display name string.               |
| `public static` | `Create(ItemType parent)`                        | `ItemType` | Creates a new instance of an item type (editor only). |
| `public`        | `UpdateAssetName()` *(Editor only)*              | `void`     | Updates the name of the asset.                        |
| `public static` | `GetFullPath(ItemType itemType)` *(Editor only)* | `string`   | Gets the full path of an item type.                   |

***

### 🧩 Nested Types

#### `public enum EnchantmentMode`

Defines the enchantment behavior of an item type.

| Name          | Description                                                    |
| ------------- | -------------------------------------------------------------- |
| `None`        | Items of this type cannot be enchanted or used for enchanting. |
| `Enchantable` | Items of this type can be enchanted.                           |
| `Enchanter`   | Items of this type can be used for enchanting.                 |
| `Both`        | Items of this type can be enchanted and used for enchanting.   |

## Creating Item Types

It's not at all recommended to create item types at runtime, but it is possible. Item types are scriptable objects which cannot be created as assets at runtime for later use. You would need to load your generated item types on your own.

```csharp
ItemType myItemType = ScriptableObject.CreateInstance<ItemType>();
```

Item type IDs must be unique. When creating item types from the [item-type-manager](https://stylishesper.gitbook.io/inventool/editors/item-type-manager "mention"), unique IDs are set automatically. However, this is not done when creating item types at runtime. You'd need to create your own method of ensuring IDs of generated item types are unique.

## Getting Item Types

### Single Item Type

You can get item types by their name or ID with the `GetItemType` method.

```csharp
ItemType myItemType = Inventool.GetItemType("My Item Type Name");
```

### Get All Item Types

```csharp
var itemTypes = Inventool.GetAllItemTypes();
```

### Get All Parent Item Types

```csharp
var itemTypes = Inventool.GetAllParentItemTypes();
```

Get All Sub Item Types

```csharp
var itemTypes = Inventool.GetAllSubItemTypes();
```
