Getting & Setting Stats

Learn how to make changes to stats.

Remember to use Esper.SkillTree.Stats namespace when scripting with stats.

Access the Stats

You can access stats by getting the UnitStatsProvider component of a GameObject.

Here's how you can get a stat called 'HP':

// Get the component
var statsProvider = GetComponent<UnitStatsProvider>();

// Get the HP stat
UpgradableStat hp = statsProvider.GetStat("HP");

You can get a stat by both its full name and abbreviation. The GetStat method returns an UpgradableStat.

Reading Stat Values

There are a few key values of an UpgradableStat to take note of.

NameDescription

baseValue

The base value of the stat. Automatically updated when the stat level is changed.

currentValue

The current value of the stat. Requires manual updates.

currentMaxValue

The max value that the current value can go up to. Automatically updated when the stat level is changed.

The current and current max values can be used to keep track of the unit's stat changes. For the HP example, the currentValue would be the unit's current HP, which should decrease as the unit gets damaged. The currentMaxValue would be the unit's HP without any damage taken.

Setting Stat Values

Updating Base and Current Max Values

These values can be changed by Upgrading Stats.

Updating Current Value

The current value should be updated manually as required by your game. You can set the current value in multiple ways.

From UnitStatsProvider

// statsProvider is a UnitStatsProvider object

// Set the current value of a stat called HP to 50
statsProvider.SetStat(50);

// Increase the current value of a stat called HP by 10
statsProvider.IncreaseStat(10);

// Decrease the current value of a stat called HP by 10
statsProvider.DecreaseStat(10);

From UpgradableStat

// HP is an UpgradableStat object

// Set the currnet value to 50
hp.SetCurrentValue(50);

// Increase the current value by 10
hp.IncreaseCurrentValue(10);

// Decrease the current value by 10
hp.DecreaseCurrentValue(10);

Last updated