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
id
The item's unique ID.
int
public
icon
The icon of the item that is displayed in the UI.
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
customObject
A custom object for any purpose.
Object
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.
Last updated