Attributes
The Attribute Manager is a component added to your character which can describe a set of values that change over time. These values are called attributes and can be used for the character’s health, shield, stamina, hunger, etc. Any number of attributes can be added to the Attribute Manager.
In this screenshot the Attribute Manager is visible and there are three attributes added: Health, Shield, and Stamina. The Stamina attribute is selected and the details will be shown for any selected attribute. Attributes can be added and removed by selecting the plus or minus icons on the bottom right of the list.
Name
The name of the attribute. This is used to identify the attribute that should be retrieved from the Attribute Manager and must be unique.
Min Value
The minimum value that the attribute’s value can be. This value cannot be greater than the Max Value.
Max Value
The maximum value that the attribute’s value can be. This value cannot be less than the Min Value.
Value
The current value of the attribute.
Auto Update Value Type
If the value isn’t at the min or max value then it can automatically be updated to reach the min or max value.
- None: The attribute will not automatically update.
- Decrease: Automatically decrease the value until the Min Value is reached.
- Increase: Automatically increase the value until the Max Value is reached.
Auto updating is useful in situations such a shield or stamina where the value should automatically regenerate to the max value. Imagine if the character is taking damage and the shield’s value is being affected by this damage. Once the character is no longer taking any damage the shield should start to regenerate back to its max value.
Auto Update Start Delay
Specifies a time (in sections) that the attribute should start to be auto updated after the attribute’s value is changed.
Auto Update Interval
After the start delay has elapsed the interval specifies how often the value is continuously updated until it reaches the target value.
Auto Update Amount
The amount value specifies the amount to add to the attribute’s current value every time the auto update occurs.
API
Get Attribute
The most common operation that you’ll perform on the Attribute Manager is to get an attribute and then modify its value. In the following code snippet an attribute will be retrieved and a value of 10 will be added to the Health attribute.
var attribute = m_AttributeManager.GetAttribute(“Health”); attribute.Value += 10;
No checks need to be performed to ensure the value stays within the Min and Max value as the value will automatically be clamped.
Value Change
You can receive notification when an attribute changes value by registering for the “OnAttributeUpdateValue” event. The actual attribute whose value was changed will be sent as the only parameter of this event.
private void OnUpdateValue(Attribute attribute) { Debug.Log("New Attribute Value:" + attribute.Value); }