Stat

3 min read

Updated on November 21, 2025

Introduction

Stat is a utility class used on a few of the other components in the system. It generally represents things like Hp and Limits.

Setting up

Stat does not inherit from MonoBehaviour therefor there is no setup required.
However if you wanted to use this utility class for yourself, simply add a Stat field to your scripts. You will then see something like this.

Settings

Current
The Current value of the Stat, this is the value that is most often changed and cannot go above Max or below 0. Generally this is started at 0 for limits, or set to the Max value for things like Hp or Mp. You can also drag the progress bar to change the Current value.

Max
The Maximum value of the Stat. Cannot be less than Current.

Infinite
If set to Infinite, any changes to Current or Max are ignored. However the Events will still trigger.

StatBar
StatBar is another component that displays the Stat in a visual bar or Dial. You can assign one here in the top left of the Stat to automatically update the StatBar when any changes are made.

Scripting

There are a few public methods available for Stat below

//Action

//Triggers when any changes are made to the Stat
public Action<float, float, float> OnValueModified;

//Example 
public void Start()
{
    stat.OnValueModified += (current, max, previous) => DoSomething(current, max, previous); 
}

/// <summary>
/// Initialise the Stat bar with a custom current and max value, seperate to what is set in the editor - useful for loading
/// </summary>
/// <param name="currentValue">The current value to set, will clamp between 0 and the max value if outside those values</param>
/// <param name="maxValue">The maximum value to set, will not go lower than the current value</param>
public void InitStat(float currentValue, float maxValue)

/// <summary>
/// Initialise the Stat bar with randomized values for current and max,
/// ensuring currentValue is clamped between 0 and maxValue.
/// </summary>
/// <param name="currentMin">The minimum possible current value before clamping</param>
/// <param name="currentMax">The maximum possible current value before clamping</param>
/// <param name="maxValueMin">The minimum possible max value</param>
/// <param name="maxValueMax">The maximum possible max value</param>
/// <param name="matchCurrentToMax">If true, currentValue will equal the randomized maxValue</param>
public void InitStatRandom(float currentMin, float currentMax, float maxValueMin, float maxValueMax, bool matchCurrentToMax = true)

/// <summary>
/// Initialises the StatBar UI if assigned
/// </summary>
public void RefreshStatBar()

/// <summary>
/// Modify the current value using positive or negative values
/// </summary>
/// <param name="amount">The amount to modify by</param>
public void Modify(float amount)

/// <summary>
/// Modify the current value absolutely. The current value will equal the amount
/// </summary>
/// <param name="amount">The amount to make the current value</param>
public void ModifyAbsolute(float amount)

/// <summary>
/// Modify the max value absolutely. The max value will equal the amount
/// </summary>
/// <param name="amount">The amount to make the max value</param>
public void ModifyMaxAbsolute(float amount)