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 / Dismantling stores. Click here to learn about item stacks.
Fields & Properties
id
The item's unique ID.
int
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
displayName
The display name of the item that is be displayed in-game.
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
weight
The amount this item weighs.
float
public
SlotCount
The number of slots that this item requires.
int
public
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 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.
Get All Items
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.
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.
SpriteType
Inventory
The inventory sprite.
SingleSlot
Single slot sprite.
Hover
The on-hover sprite.
KeyItem
The key item sprite.
Shop
The shop sprite.
Last updated