Item Binding

The Item Binding component allows you to bind an item attribute to any property of the same type. This means that when the attribute value is retrieved, it will use the property to get the value. Similarly, when an attribute value is set, it will use the property to set the value. This makes synchronizing data extremely easy. The category of the item must be specified ahead of time. This is because the Item Category determines what attributes the item contains.

New bindings can be setup by performing the following:

  • Select the GameObject that you’d like to add the binding to. This GameObject should be the visible representation of your item.
  • Add the Item Object (or Usable Item Object) component to your GameObject.
  • Add the Item Binding component to your GameObject.
  • Select the database and the category for the attribute that you’d like to bind.
  • Specify the component that contains the property that you’d like to bind.
  • Select the property that you’d like to bind to the attribute.

In the example below we setup a binding between the NumOfProjectiles attribute with the BulletsPerFire property.

The Item Binding component works on properties, and not field. In the example above the BulletsPerFire property looks like:

// This is a field.
[SerializeField] protected int m_BulletsPerFire;

// This is a property.
public int BulletsPerFire
{
    get => m_BulletsPerFire;
    set => m_BulletsPerFire = value;
}

You can now set the ItemObjects Item at any time in the game and your RangeAttack “BulletsPerFire” property will always match the items “NumOfProjectiles” attribute value.