Appearance
Ability Sample
This walkthrough follows ShowcaseSprintAbility in the Compact Multiplayer Showcase.
The complete loop
- The ability is granted to
ShowcaseCharacter. AbilityInputSettingsbinds it to the sprint network input.CanActivaterequires positive Stamina after base policies pass.Activateenables the movement multiplier.- Every Fusion tick removes Stamina through
AttributeContainer.ApplyModifier. - Releasing input, interruption, or reaching zero Stamina exits the loop.
finallyalways 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.