Skip to content

Ability Sample

This walkthrough follows ShowcaseSprintAbility in the Compact Multiplayer Showcase.

The complete loop

  1. The ability is granted to ShowcaseCharacter.
  2. AbilityInputSettings binds it to the sprint network input.
  3. CanActivate requires positive Stamina after base policies pass.
  4. Activate enables the movement multiplier.
  5. Every Fusion tick removes Stamina through AttributeContainer.ApplyModifier.
  6. Releasing input, interruption, or reaching zero Stamina exits the loop.
  7. finally always disables sprinting.

The important detail is cleanup. Ability execution may end through several paths, so temporary movement state is restored in finally and also guarded by OnButtonReleased.

csharp
while (!context.Interrupted &&
       context.AbilitySystem.IsInputPressed(InputSettings.Input) &&
       character.Stamina > 0f)
{
    character.Attributes.ApplyModifier(
        ShowcaseCharacter.StaminaAttribute,
        ModifierOperation.Additive,
        -staminaPerSecond * context.AbilitySystem.Runner.DeltaTime);

    yield return new AbilityWaitTicks(1);
}

Compare it with Jump, which has a fixed action and cooldown, and weapon fire/reload, which resolve the currently equipped Weapon. Then use Manual: Abilities to build your own.

RedEngine Framework documentation