-
Notifications
You must be signed in to change notification settings - Fork 196
Initialising Stats
Before we can interact with character attributes using abilities, we need to set up our character's starting stats. We do this by using a special type of ability - Stat Initialisation
Ability.
Create a new Stat Initialisation Ability
via the Assets | Create | Gameplay Ability System | Abilities | Stat Initialisation
menu, and call it Player Initial Stats
. Set the Ability Name
to Player Initial Stats
in the Inspector.
We can define optional Cost and Cooldown Gameplay Effects
, but our ability won't use these, so we will leave them blank.
The Initialisation GE
list contains which Gameplay Effects
to apply to the character. We want our character to start with 5 health, so we need to create a Gameplay Effect
:
- Create a new
Gameplay Effect
via theAssets | Create | Gameplay Ability System | Gameplay Effect Definition
menu, and name itPlayer Initial Health Gameplay Effect
- Configure the
Gameplay Effect
to grant 5 health instantly:
Assign the Gameplay Effect
to the Initialisation GE
list in the Player Intial Stats
ability.
Now, we need some way of activating this ability when the game starts. Activating an ability is a simple two step-procedure:
AbstractAbilitySpec abilitySpec = ability.CreateSpec(abilitySystemCharacter);
StartCoroutine(abilitySpec.TryActivateAbility());
So, we'll create a MonoBehaviour
on our player which activates the ability on Awake()
.
public class InitialStatsBehaviour : MonoBehaviour
{
[SerializeField] private AbstractAbilityScriptableObject ability;
[SerializeField] private AbilitySystemCharacter abilitySystemCharacter;
void Awake()
{
AbstractAbilitySpec abilitySpec = ability.CreateSpec(abilitySystemCharacter);
StartCoroutine(abilitySpec.TryActivateAbility());
}
}
Press Play to test the ability. You should see that the player has 5 health.