# Ability System Component (ASC)

This is the container that holds all the "gears" of the GameplayAbilitySystem. \
It represents a single character/entity with its **Attributes**/**Abilities** and **Effects**/**Tags** currently applied to it. \
It is also the origin of most things that are executed by the GAS.

<figure><img src="https://585731495-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPvnvgshL169KwwsLUx0q%2Fuploads%2FElRmcgaEywMk8HhH9VCW%2Fimage.png?alt=media&#x26;token=3f63adb1-5860-4ac7-b198-1c37e388d6c3" alt=""><figcaption><p>AbilitySystemComponent (ASC) in the inspector.</p></figcaption></figure>

## Attributes

The **Attributes** in this **ASC** and their current values. \
**Attributes** are numeric representations of any mechanic/parameter you are modelling.&#x20;

You can create as many different attributes as you want to represent any numeric mechanic. The only limit is your imagination. This is not constrained to your player, or combat related values, you can create mechanics for other objects aswell, including crafting, vehicles, basebuilding.

_(e.g. Health, MaxHealth, MovementSpeed, CriticalChance, CriticalBonus, Ammo, Dungeon.SpawnRate, Building.MaxRooms, Vehicle.Acceleration, Monster.HitChance, Enemy.AimSpeed)_

Check [attributes](ability-system-component-asc/attributes "mention") to create more attributes.

### OnAttributeChanged

Subscribe to this event to update your variables whenever an attribute changes.

```csharp
asc.OnAttributeChanged += (attributeName, oldValue, newValue, ge) => { Debug.Log($"{attributeName.name} {oldValue} -> {newValue} / ge: {ge?.name}"); };
```

### GetAttribute

Use this to grab an attribute value immediately. \
Needs to be called every frame if you need to keep the variable always up to data. \
Prefer OnAttributeChanged.

## Tags

Current **GameplayTags** applied on this **ASC**.\
**GameplayTags** are names used to classify and describe the state of an object.\
They are useful for categorizing and identifying the properties or status of an entity (**ASC**).

_(e.g. Status.Debuff.Stun, Status.Debuff.Poisoned, Movement.Crouching, Movement.Sprinting, Environment.Underwater)_

### OnTagsChanged

This event is triggered everytime the **ASC**'s **tags** are changed.

```csharp
 asc.OnTagsChanged += (newTags, src, tgt) => Debug.Log($"[TAGS] OnTagsChanged! newTags: [{string.Join(", ", newTags.Select(x => x.name))}]");
```

## GrantedGameplayAbilities

List of abilities (GA) the **ASC** can use/activate.

### TryActivate

Attempts to activate a specific **GameplayAbility** by its name, index or reference. It searches for the ability in the list of _grantedGameplayAbilities_ and then attempts to activate it on a specified target.

### Grant/Ungrant Ability

Granting an ability instantiates a new copy of the **GameplayAbility** and add that copy to **grantedGameplayAbilities**. Also triggers _OnGameplayAbilityGranted_ event.\
Ungranting deactivates the ability and then remove it from **grantedGameplayAbilities.** Also triggers _OnGameplayAbilityUngranted_ event.

## AppliedGameplayEffects

Current **GameplayEffects** applied on this ASC.

### ApplyGameplayEffect/RemoveGameplayEffect

The **ApplyGameplayEffect** method is called by **Abilities** (GA). It applies a **GameplayEffect** (GE) to an AbilitySystemComponent (ASC). It sets the source and target for the effect, then checks if the effect meets the tag requirements. If the requirements are met, it applies the effect and triggers _OnGameplayEffectApplied_. **ApplyGameplayEffect** can also be called 'manually' if you want to apply an effect (GE) without an ability.

The **RemoveGameplayEffect** method removes a gameplay effect from the ASC. It first checks if the effect is present in the ASC. If found, it removes the effect, refreshes attribute modifiers, applies attribute modifier values, and triggers _OnGameplayEffectRemoved_.

## Events

There are events that you can listen for and react to changes on the **ASC**.

_OnGameplayEffectApplied, OnGameplayEffectRemoved_\
Triggered when GameplayEffects are applied or removed.

_OnTagsChanged_\
Triggered when the applied tag list of the ASC changes.

_OnGameplayAbilityGranted, OnGameplayAbilityUngranted_\
Triggered when an ability is granted or ungranted.\
\
&#xNAN;_&#x4F;nGameplayAbilityPreActivate, OnGameplayAbilityActivated, OnGameplayAbilityTryActivate, OnGameplayAbilityDeactivated, OnGameplayAbilityFailedActivation_\
Triggered when activating/deactivating abilities.\
\
&#xNAN;_&#x4F;nAttributeChanged, OnPreAttributeChange_\
Triggered from changes in attributes.



