How-To: Use Toggle, Charges and Channeling

Goal: pick the right shipped ability shape instead of re-implementing it.

Prerequisites
Quick Start.

Toggle

UCrimsonGameplayAbility_Toggle stays active until the input is pressed again. Use it for stances, auras and sustained modes. Its buff effect, its recurring costs and its tick abilities all come from the contract - see How-To: Set Up a Toggle Ability for the full walkthrough.

How the shipped Toggle sees the second press
InputPressed and InputReleased only fire on the locally controlled client, so an override cannot tell the server the toggle went off. UCrimsonGameplayAbility_Toggle listens with a replicated UAbilityTask_WaitInputPress instead: the client RPCs the press through the ability-task pipeline and the server ends the ability itself. Copy that pattern in any hand-rolled ability that stays active across presses.
EventRuns onUse for
On Toggled On (Cosmetic), On Toggled Off (Cosmetic)Server and predicting clientVFX, sound, UI state.
On Toggled On (Authority), On Toggled Off (Authority)Server onlySpawn actors, apply gameplay effects.
Toggle cost and cooldown are separate decisions
Cost Gameplay Effect Class is committed on activation. The cooldown is not tied to that: Cooldown Policy chooses whether it starts when the toggle turns on, when it turns off, at both ends, or only when you call Trigger Toggle Cooldown. The recurring drain is the contract's Periodic Costs, each on its own interval; if one becomes unaffordable at its own moment the toggle ends.

Charges

UCrimsonGameplayAbility_Charges holds N uses that refill over time. Read state with Get Max Charges and Get Current Charges; activation fails with Ability.ActivateFail.Charge.OutOfCharges when empty.

Bind a UI widget to Get Current Charges and listen for Ability.ActivateFail.Charge.OutOfCharges to flash the button.

Charge count is server-authoritative
ChargesUsed is mutated only on the server and sent to the owning client by a reliable RPC, so Get Current Charges updates about half a round trip after the press. Bind UI to the OnChargesChanged delegate rather than reading the count immediately after activating.

Channeling

UCrimsonGameplayAbility_Channeling ticks at an interval while held and can break on movement.

FunctionDoes
Start Channeling / Stop ChannelingBegin and end the channel explicitly.
Set Channel Tick IntervalHow often the channel ticks.
Set Max Channel TimeHard cap on the channel duration.
Set Cancel On MovementBreak the channel if the avatar moves.

The tick heartbeat runs on both machines. Per-tick gameplay belongs in the authority event.

EventRuns onUse for
On Channeling Started (Cosmetic), On Channeling Tick (Cosmetic), On Channeling Stopped (Cosmetic)Server and predicting clientBeam VFX, sound, UI.
On Channeling Started (Authority), On Channeling Tick (Authority), On Channeling Stopped (Authority)Server onlyDamage ticks, spawning, resource drain.
Hold and Toggle both replicate their stop signal
Channeling Input Type = Hold waits on UAbilityTask_WaitInputRelease; Toggle waits on UAbilityTask_WaitInputPress. Both replicate to the server, so the server ends the channel on its own rather than being told to by the client. Cancel On Movement is likewise evaluated only on the server.
Verify
Channel, then move. With Cancel On Movement set, the ability ends and Ability.State.Channeling is removed.

See also

  • How-To: Set Up a Toggle Ability
  • How-To: Make a Cast-Time Ability
  • Concept: Ability Subclasses