Creating New Abilities

To create new ability types, just inherit from the base GameplayAbility class.

Instantiate: Creates a new GA instance, this is used to get copy the ability data from a ScriptableObject into a runtime version of the ability. Anything that need to be copied from the original SO when the ability is granted, should be done here.

An Ability has 3 activation steps: PreActivate, Activate, PostActivate.

PreActivate sets initial data (isActive, source/target, etc...) Activate applies cost/cooldown. This is what you should generally override for your ability. (e.g. InstantAbility overrides this, calls base.Activate() and ApplyEffects and deactivates immediately). PostActivate the ability has completely activated.

CanActivate and CheckCost can also be overriden for custom behavior (e.g. ShootAbility - Check ammo cost on inventory)

ScriptableObject

Also, create an ScriptableObject container to be able to create its asset. e.g.:

namespace GAS {
    [CreateAssetMenu(menuName = "GAS/GameplayAbilitySO_InstantAbility", fileName = "GA_InstantAbility")]
    [Serializable]
    public class GameplayAbilitySO_InstantAbility : GameplayAbilitySO {
        public GameplayAbilitySO_InstantAbility() {
            ga = new InstantAbility();
        }
    }
}

Last updated