Enchanter

Scripting with the Enchanter class.

An Enchanter is a merchant that enchants items.

Fields & Properties

Name
Description
Type
Access

enchantTargets

The types of items this enchanter can enchant.

Enchanter.EnchantTargets

public

supportedItemTypes

A list of item types this enchanter can enchant.

List<ItemType>

public

supportedItems

A list of items that this enchanter can enchant.

List<Item>

public

Enchant Targets

Enchanter.EnchantTargets is an enum that helps define the items an enchanter can enchant.

Name
Description

Everything

Can enchant any item.

SpecificItemTypes

Can only enchant items of the item types listed in the supportedItemTypes field.

SpecificItems

Can only enchant items listed in the supportedItems field.

Creating Enchanters

It's not recommended to create enchanters at runtime, but it is possible. Enchanter is a scriptable object which cannot be created as an asset at runtime for later use.

Enchanter myEnchanter = ScriptableObject.CreateInstance<Enchanter>();

Enchanting

An Enchanter requires a reference to Enchanter Items and Enchantable Items.

You can check if it's possible to enchant an item with the CanEnchant method. The first parameter is the enchantable item, the second is the enchanter item, and the third is abool that determines if the failure reason should be invoked. This method will return true if the enchanter can enchant the enchantable item. Otherwise, false will be returned.

bool result = myEnchanter.CanEnchant(myEnchantableItem, myEnchanterItem, true);

To officially enchant an item, use the TryEnchant method. This is similar to the CanEnchant method, except it will enchant the item if successful.

bool result = myEnchanter.TryEnchant(myEnchantableItem, myEnchanterItem);

Last updated