> For the complete documentation index, see [llms.txt](https://espergames.gitbook.io/inventool/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://espergames.gitbook.io/inventool/scripting/character-stats.md). Agents can also search and read this documentation through its [MCP server](https://espergames.gitbook.io/inventool/~gitbook/mcp).

# Character Stats

A class used to provide stats to a GameObject.

## Notes

* All properties visible in the component inspector can be accessed through code.

## Initialize

Initialization sets up stat events. This is usually handled automatically, but you can initialize manually by calling the `Initialize` method.

```csharp
myCharacterStats.Initialize();
```

Use `Uninitialize` to have the opposite effect.

```csharp
myCharacterStats.Uninitialize();
```

## Leveling

You can use the `Level` and `MaxLevel` properties to check the current and max levels. However, these are read-only. To actually manage the character's level, `SetLevel`, `SetMaxLevel`, `LevelUp`, or `LevelDown` methods.

```csharp
myCharacterStats.LevelUp(); // Increases level by one
```

### Exp

Another, more common, way to manage levels is by using the `AddExp` and `RemoveExp` methods.

```csharp
myCharacterStats.AddExp(10); // Increases EXP by 10 points
```

To check the current EXP state, use the `Experience` property. `Experience` is a [Scaling Value](https://espergames.gitbook.io/inventool/scripting/stats/scaling-value.md).

## Durability

{% hint style="info" %}
Durability usually doesn’t make sense for characters, but it exists because characters and items share the same stat class.
{% endhint %}

To manage durability, use the `AddDurability` or `RemoveDurability` methods.

<pre class="language-csharp"><code class="lang-csharp"><strong>myCharacterStats.AddDurability(10); // Increases durability by 10 points
</strong></code></pre>

To check the current durability state, use the `Durability` property. `Durability` is a [Scaling Value](https://espergames.gitbook.io/inventool/scripting/stats/scaling-value.md).

## Stats

All stats can be accessed with the `Stats` list property. To learn how to work with individual stats, visit the [Stat](https://espergames.gitbook.io/inventool/scripting/stats/stat.md) page.

You can check if a specific stat exists with the `HasStat` method.

```csharp
if (myCharacterStats.HasStat("HP")) // Checks if the HP stat exists
{
    // Do something...
}
```

To get a specific stat, use the `GetStat` method.

```csharp
Stat hp = myCharacterStats.GetStat("HP");
```

Stats are stored inside the `profile` field. Also see [Stat Profile](https://espergames.gitbook.io/inventool/scripting/stats/stat-profile.md).

### Merging

You can merge external stats with the `MergeStats` method. This is useful when you need to **permanently** add stats to the character.

```csharp
myCharacterStats.MergeStats(hpStat, defStat); //... atkStat etc.
```

### Combining

You can combine external stats with the `CombineStats` method. This is useful for stats that should be added to the character **temporarily**.

```csharp
myCharacterStats.CombineStats(hpStat, defStat); //... atkStat etc.
```

Use the `UncombineStats` method to have the opposite effect.

```csharp
myCharacterStats.UncombineStats(hpStat, defStat);
```

### Equipment

Adding equipment references combines the stats of the equipment with the character's stats. You can manage equipment with the `SetEquipment`, `UnsetEquipment`, `AddEquippedItem`, and `RemoveEquippedItem` methods.

```csharp
myCharacterStats.AddEquippedItem(myEquipmentItem);
```

## Saving

See [Character Stats](https://espergames.gitbook.io/inventool/scripting/saving-and-loading/character-stats.md).

## Events

| Name               | Type       | Description                                                                                                                                     |
| ------------------ | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| onDurabilityZero   | UnityEvent | A callback for when the durability of this character reaches zero.                                                                              |
| onLeveledUp        | UnityEvent | A callback for when this character is leveled up.                                                                                               |
| onLeveledDown      | UnityEvent | A callback for when this character is leveled down.                                                                                             |
| onAnyUpdated       | UnityEvent | A callback for when any stat or scaling value is updated. To add callbacks to more specific events, access the Stat or ScalingValue themselves. |
| onEquipmentChanged | UnityEvent | A callback for when the equipped items list is changed.                                                                                         |
