book-sparklesAbilities System Structure

Abilities Manager

The AbilitiesManager is located in the Game scene hierarchy under the Stage Controller GameObject.

It provides a variety of useful methods for manipulating abilities, such as:

  • Adding or removing an ability

  • Increasing or decreasing an ability’s level

  • Retrieving all acquired abilities

  • Retrieving all available abilities

You can access it in code via the property:

StageController.AbilitiesManager

All methods of AbilitiesManager are declared as virtual. If you want to modify or extend its functionality, it is recommended to create a new class that inherits from it rather than editing the original directly.

Ability Database

The Ability Database asset stores references to all Ability Data assets used in the game. It serves as a central point for managing abilities and their rarities. Other tools, such as the Abilities Tester, can only operate on abilities included in this database.

Fields:

  • Abilities - A list of all Ability Data assets available in the game. Only abilities from this list can be accessed by other systems (e.g., the Abilities Tester or Abilities Selector).

  • Rarities - A list of Rarity Data entries. Each entry defines a rarity type, its display name, color, and the probability of being selected by the Abilities Selector.

  • Reroll Abilities Cost - The amount of gold the player must spend to reroll the available abilities in the Abilities Selector.

Ability Data

Every ability in the template has its own Ability Data class, which inherits from GenericAbilityData<T>, itself derived from the abstract AbilityData class.

AbilityData.cs contains the following key fields:

Property
Description

AbilityType type

An enum value that uniquely identifies the ability. There must not be two abilities with the same type. This value is usually assigned in the Awake and OnValidate methods of the specific Ability Data class to prevent accidental modification.

List<AbilityType> prerequisites

A list of required abilities. The Abilities Selector will only consider showing this ability if all prerequisite abilities have already been acquired.

AbilityRarity rarity

An enum that defines the rarity of the ability. Possible values: Common, Rare, Mystical, or Legendary. The rarer the ability, the less likely it is to appear. The Abilities Selector shows only abilities of the same rarity at a time, and the Ability Card UI uses different visuals for each rarity.

bool isRepeatedAbiltiy

If true, this ability can always be proposed to the player, even if it has already been acquired or is at its maximum level. Examples include Heal Ability or other endgame abilities.

bool isEndgameAbility

If true, this ability will only be considered by the Abilities Selector when no other abilities of the same rarity remain available.

string title

The display name of the ability. Shown on the Ability Card UI and above the player when the ability is acquired.

string description

The display description of the ability. Shown on the Ability Card UI.

Sprite icon

The ability’s icon, shown on the Ability Card UI and in the Pause Menu if the ability is active.

GameObject prefab

The prefab that represents this ability. Its root object must include an Ability Behavior component that defines the ability’s functionality.

You can subscribe to the onAbilityUpgraded event to execute custom code when the ability is upgraded.

GenericAbilityData is a generic intermediary class between AbilityData and the actual implementation of an ability’s data class. Its generic parameter T must be a subclass of AbilityLevel - an empty marker class used to define individual ability level data.

Each Ability Data instance contains a list of Ability Levels, specific to that ability.

Here's an example of an actual Ability Data class:

circle-info

Note: The underscore symbol in AbilityType.Buff_Combo separates the category (“Buff”) from the ability name (“Combo”). The template includes 80 abilities, so a custom property drawer is used to organize them into categories for easier access.

Here's how the Combo Ability Data inspector looks like

Ability Behavior

Each ability must have its own prefab with a component that inherits from the generic abstract class:

where:

  • T - the ability data class

  • K - the ability level class

This base class provides several commonly overridden methods used to control ability initialization, level updates, and cleanup.

Commonly Overridden Methods

Called once when the ability is activated. Subsequent level changes do not trigger this method.


Called once together with Init. Use this when you need to ensure that the ability data is initialized before performing setup logic.


Called when the ability is first activated and every time its level changes. Override this method to adjust the ability’s behavior or values when its level changes.


Called when the ability is removed. By default, it destroys the ability’s GameObject. If you override this method, make sure to call base.Clear() at the end to ensure proper cleanup.


Below is an example of a Major Power Boost Ability behavior class that modifies the player’s attack damage stat.

Last updated