Item

Scripting with the Item class.

While it may seem like the Item class is the main class you'll be working with, it's actually not. Chances are, you'll be using the ItemStack class far more. Basically, the Item class is like an ID for an ItemStack, and the ItemStack class is what is the inventory stores. Click here to learn about item stacks.

Fields & Properties

Name
Description
Type
Access

id

The item's unique ID.

int

public

itemClass

The class of the item.

ItemClass

public

currencyPouch

The currency pouch that defines the currency gained when this item is obtained. This is only relevant when item class is set to Currency.

CurrencyPouch

public

icon

The icon of the item that is displayed in the inventory.

Sprite

public

singleSlotIcon

The icon of the item that is displayed in an item slot that is the size of a single slot.

Sprite

public

hoverImage

An image that represents the item. This will be used for the hover details popup.

Sprite

public

keyItemsImage

An image that represents the item. This will be used in the key item section.

Sprite

public

inventoryBackgroundImage

The background image of the item when in the inventory.

Sprite

public

singleSlotBackgroundImage

The background image of the item when in an item slot the size of a single slot.

Sprite

public

hoverBackgroundImage

The background image of the item in the hover details popup.

Sprite

public

shopBackgroundImage

The background image of the item in the shop.

Sprite

public

profile

The stat profile of this item.

StatProfile

public

enchantmentLimit

A hard limit on the number of times this item can be enchanted. This is only relevant if the enchantment limit type is set to Individual in settings.

int

public

displayName

The display name of the item that is be displayed in-game.

string

public

localizedDisplayNameKey

The key of the localized display name string.

string

public

itemType

The type of this item.

ItemType

public

description

The description of the item that is displayed in-game.

string

public

currencyIdentity

The currency identity that is used for the costs.

CurrencyIdentity

public

buyingPrice

The price of the item when purchasing from vendors.

Currency

public

sellingPrice

The price of the item when selling to vendors.

Currency

public

overrideDropPrefab

An item drop prefab that overrides the default item drop that is spawned on drop.

GameObject

public

customObject

A custom object for any purpose.

Object

public

dismantleResult

The items gained when this item is dismantled.

List<ItemStack>

public

enchantment

The enchantment that this item provides when it is used to enchant another item.

Enchantment

public

size

The amount of space (slots) this item takes up in the inventory.

Vector2Int

public

hideStats

If stats of this item should not be displayed normally when hovered.

bool

public

SlotCount

The number of slots that this item requires.

int

public

Item Class

Name
Description

Normal

Represents a custom item. The item will be treated as normal.

Currency

An item that represents a currency. The item itself won't appear in the inventory. When obtained, it simply adds its currency amount to the player's inventory.

Creating Items

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

Item myItem = ScriptableObject.CreateInstance<Item>();

Item IDs must be unique. When creating items from the Items tab, unique IDs are set automatically. However, this is not done when creating items at runtime. You'd need to create your own method of ensuring IDs of generated items are unique.

Getting Items

Items created through the Items tab can be retrieved at runtime.

Get a Single Item

You can get an item by its ID or display name with the Inventool.GetItem method.

Item myItem = Inventool.GetItem("My Item Name");

Get All Items

var items = Inventool.GetallItems();

Creating an Item Stack

You can create an Item Stack from an Item with the CreateNewItemStack method. This method accepts a integer which represents the stack amount. Note that if an item is not stackable, it will always create a stack of 1.

// Create an item stack of 10
ItemStack myItemStack = myItem.CreateNewItemStack(10);

Getting Icon/Background

You can get a specific item image or background with the GetSprite and GetBackground methods. These methods are generally good to use because they will fallback to an available sprite if the one requested was not set.

var sprite = myItem.GetSprite(spriteType);
var background = myItem.GetBackground(spriteType);

SpriteType

Name
Description

Inventory

The inventory sprite.

SingleSlot

Single slot sprite.

Hover

The on-hover sprite.

KeyItem

The key item sprite.

Shop

The shop sprite.

Interpolated Description

You can get the item description with text interpolation with the GetInterplatedDescription method. This essentially helps display stats in item descriptions. Read more about this here.

string description = myItem.GetInterpolatedDescription();

Last updated