$npx -y skills add quodsoler/unreal-engine-skills --skill ue-gameplay-abilitiesUse this skill when working with GAS, Gameplay Ability System, GameplayAbility, GameplayEffect, AttributeSet, GameplayTags, ability system, buffs, debuffs, cooldowns, or attribute modification. See references/ for detailed setup patterns, effect configuration, and ability task us
| 1 | # Gameplay Ability System (GAS) |
| 2 | |
| 3 | You are an expert in Unreal Engine's Gameplay Ability System (GAS). |
| 4 | |
| 5 | ## Context Check |
| 6 | |
| 7 | Before proceeding, read `.agents/ue-project-context.md` to determine: |
| 8 | - Whether the GameplayAbilities plugin is enabled |
| 9 | - Which actors own the AbilitySystemComponent (PlayerState vs Character) |
| 10 | - The replication mode in use (Minimal, Mixed, Full) |
| 11 | - Any existing AttributeSets or ability base classes |
| 12 | |
| 13 | ## Information Gathering |
| 14 | |
| 15 | Ask the developer: |
| 16 | 1. What type of abilities are needed? (active, passive, triggered, instant) |
| 17 | 2. What attributes are required? (health, mana, stamina, custom stats) |
| 18 | 3. Is this multiplayer? If so, which actors carry the ASC? |
| 19 | 4. Are cooldowns and costs required, or is this a passive/trigger system? |
| 20 | 5. Do abilities need prediction (local-only feedback before server confirms)? |
| 21 | |
| 22 | --- |
| 23 | |
| 24 | ## GAS Architecture Overview |
| 25 | |
| 26 | GAS has three pillars that live on `UAbilitySystemComponent` (ASC): |
| 27 | |
| 28 | | Pillar | Class | Purpose | |
| 29 | |--------|-------|---------| |
| 30 | | Abilities | `UGameplayAbility` | Logic for what happens when activated | |
| 31 | | Effects | `UGameplayEffect` | Data-driven stat mutations (instant, duration, infinite) | |
| 32 | | Attributes | `UAttributeSet` | Float properties representing character stats | |
| 33 | |
| 34 | GameplayTags thread through all three as requirements, grants, and blockers. |
| 35 | |
| 36 | --- |
| 37 | |
| 38 | ## GAS Setup |
| 39 | |
| 40 | ### 1. Enable the Plugin |
| 41 | |
| 42 | Enable `GameplayAbilities` in `.uproject` Plugins array, then in `[ProjectName].Build.cs`: |
| 43 | ```csharp |
| 44 | PublicDependencyModuleNames.AddRange(new string[] |
| 45 | { |
| 46 | "GameplayAbilities", "GameplayTags", "GameplayTasks" |
| 47 | }); |
| 48 | ``` |
| 49 | |
| 50 | ### 2. AbilitySystemComponent Ownership |
| 51 | |
| 52 | **PlayerState (recommended for multiplayer):** ASC persists across respawns because PlayerState |
| 53 | is not destroyed on death. Use this for player characters in networked games. |
| 54 | |
| 55 | **Character/Pawn:** Simpler. Use for AI characters or single-player games where persistence |
| 56 | across respawns is not required. |
| 57 | |
| 58 | See `references/gas-setup-patterns.md` for full initialization sequences for both patterns. |
| 59 | |
| 60 | ### 3. IAbilitySystemInterface |
| 61 | |
| 62 | Every actor that owns or exposes an ASC must implement `IAbilitySystemInterface`: |
| 63 | |
| 64 | ```cpp |
| 65 | #include "AbilitySystemInterface.h" |
| 66 | |
| 67 | UCLASS() |
| 68 | class AMyCharacter : public ACharacter, public IAbilitySystemInterface |
| 69 | { |
| 70 | GENERATED_BODY() |
| 71 | public: |
| 72 | virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override |
| 73 | { return AbilitySystemComponent; } |
| 74 | UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "GAS") |
| 75 | TObjectPtr<UAbilitySystemComponent> AbilitySystemComponent; |
| 76 | }; |
| 77 | ``` |
| 78 | |
| 79 | ### 4. Replication Modes |
| 80 | |
| 81 | Set on the ASC after creation (server-side only): |
| 82 | |
| 83 | ```cpp |
| 84 | // In BeginPlay or PossessedBy on the server: |
| 85 | AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Mixed); |
| 86 | ``` |
| 87 | |
| 88 | | Mode | When to Use | |
| 89 | |------|-------------| |
| 90 | | `Minimal` | AI or non-player actors; no GE replication to simulated proxies | |
| 91 | | `Mixed` | Player-controlled characters (owner gets full info, others get minimal) | |
| 92 | | `Full` | Non-player games or debugging; all GEs replicate to all clients | |
| 93 | |
| 94 | ### 5. InitAbilityActorInfo |
| 95 | |
| 96 | Must be called on both server and client after possession. Call in `PossessedBy` (server) |
| 97 | and `OnRep_PlayerState` (client): `ASC->InitAbilityActorInfo(OwnerActor, AvatarActor)`. |
| 98 | See `references/gas-setup-patterns.md` for full dual-path code with respawn handling. |
| 99 | |
| 100 | --- |
| 101 | |
| 102 | ## GameplayAbilities |
| 103 | |
| 104 | ### Subclass UGameplayAbility |
| 105 | |
| 106 | ```cpp |
| 107 | #include "Abilities/GameplayAbility.h" |
| 108 | |
| 109 | UCLASS() |
| 110 | class UMyFireballAbility : public UGameplayAbility |
| 111 | { |
| 112 | GENERATED_BODY() |
| 113 | public: |
| 114 | UMyFireballAbility(); |
| 115 | virtual void ActivateAbility(const FGameplayAbilitySpecHandle Handle, |
| 116 | const FGameplayAbilityActorInfo* ActorInfo, |
| 117 | const FGameplayAbilityActivationInfo ActivationInfo, |
| 118 | const FGameplayEventData* TriggerEventData) override; |
| 119 | virtual void EndAbility(const FGameplayAbilitySpecHandle Handle, |
| 120 | const FGameplayAbilityActorInfo* ActorInfo, |
| 121 | const FGameplayAbilityActivationInfo ActivationInfo, |
| 122 | bool bReplicateEndAbility, bool bWasCancelled) override; |
| 123 | // Ability Tasks — async building blocks for latent abilities: |
| 124 | // UAbilityTask_WaitTargetData — waits for targeting (crosshair/AoE confirm) |
| 125 | // UAbilityTask_WaitGameplayEvent — waits for a GameplayEvent tag (e.g., anim notify) |
| 126 | // UAbilityTask_WaitDelay — simple timer |
| 127 | // UAbilityTask_PlayMontageAndWait — montage with callbacks (see ue-animation-system) |
| 128 | // See references/ability-task-reference.md for full list and custom task pattern. |
| 129 | // CancelAbility — called by CancelAbilitiesWithTag or ASC->CancelAbility(Handle) |
| 130 | // Internal |