Stat Modifiers¶
We've seen so far that objects with a Traits component can change their Stat and Attribute values at runtime using Formulas and Tables. However, characters in games can also increment/decrement their stats when equipping weapons and other kinds of wearables.
This is where Stat Modifiers come into play: They increase or decrease a Stat value by a certain amount, and can be added and removed at any time.
Adding Stat Modifiers¶
To add a Stat Modifier to a Traits component, use the visual scripting Instruction Add Stat Modifier. This instruction allows you to specify a target object, which must have a Traits component, a Stat to affect and a value.
This value can either be a percentage or a constant and can be displayed separately in the UI. Percentage values are expressed as a ratio: a value of 0.1 increases the Stat by 10%, while a value of -0.25 decreases it by 25%.

Percentage and Constants
You may have raised an eyebrow when Stat Modifiers can use constant and percentage values, as the result is different when applying a product after an addition or vice versa. The Stats module always applies percentage based modifiers first, and then adds any constant modifiers.
For example, a Stat with a final value of 100 that has a +0.1 percentage modifier and a +5 constant modifier will end up with a value of 115 (100 x 1.1 + 5). Note that modifiers are applied after the Stat's Formula (if any) has been calculated.

Removing Stat Modifiers¶
Removing a Stat Modifier is as easy as adding one. All that needs to be done is to use the visual scripting instruction Remove Stat Modifier and input the same values (target, Stat, type and value) as a previously added one.

Modifiers from code¶
Stat modifiers can also be added and removed from a script, using the runtime data of the Stat found in the Traits component:
using GameCreator.Runtime.Stats;
using UnityEngine;
public class MyBuff : MonoBehaviour
{
public Traits traits;
public Stat strength;
public void Apply()
{
RuntimeStatData data = this.traits.RuntimeStats.Get(this.strength.ID);
data.AddModifier(ModifierType.Percent, 0.1);
}
public void Revoke()
{
RuntimeStatData data = this.traits.RuntimeStats.Get(this.strength.ID);
data.RemoveModifier(ModifierType.Percent, 0.1);
}
}