The StatHub plugin comprises several components, mainly the Hub, containers, stats, and modifiers.

(Make sure the plugin is enabled before trying to access it!)

Let’s create a new scene of any type and then create a StatContainer node as a child.

Now, let’s start by creating a SimpleStat as a child of the StatContainer. You should notice a field appears in the inspector named “Base Value”: This is the value of the stat before modifiers are applied and therefore when no modifiers are attached, it will be the resulting value. Assign this a value of your choice (it will be 5 for this example).

To test, let’s add a script to the scene’s root node. Make sure to add an export for the new SimpleStat (which can be Stat), and print the stat’s Value on ready. It should look like the following:

using Godot;
using StatHub;

public partial class TestScript : Node
{
    [Export]
    public Stat testStat;
    
    public override void _Ready()
    {
        GD.Print(testStat); // alternatively: GD.Print(testStat.Value);
    }
}
extends Node

@export var test_stat : Stat

func _ready():
	print(test_stat) # alternatively: print(test_stat.Value)

Running this should print the base value that you input previously.

Modifiers

But what if you want to modify the value of the stat? Say you want to add 10 to your stat’s base value at some point: You want a StatModifier.

You can create a new SimpleModifier by creating a new resource via the file system. Inside the new modifier’s inspector, you should see a “Modification Option” drop-down with the options FLAT_ADDITIVE (adds a number to the input) and PERCENT_ADDITIVE (adds a percentage of the input to the input). Choose one of these options and input a corresponding value into the “Base Modification Amount” field you would like to try (for this example, FLAT_ADDITIVE and an amount of 10–equivalent to $input + 10$).

Now, let’s add an export for the modifier in our script and attach it to the stat. The implementation of that might look like this:

using Godot;
using StatHub;

public partial class TestScript : Node
{
    [Export]
    public Stat testStat;
    
    [Export]
    public StatModifier testModifier;
    
    public override void _Ready()
    {
        GD.Print(testStat);
        
        testStat.AttachModifier(testModifier);
        GD.Print(testStat);
    }
}