RealDocs

UAbilitySystemComponent::GiveAbility

function GameplayAbilities Blueprint Since unknown
#include "AbilitySystemComponent.h"
Access: public Specifiers: BlueprintAuthorityOnly

Description

Grants an ability to this component so it can later be activated. Returns a handle that identifies the granted ability for future TryActivateAbility or RemoveAbility calls.

Signature

UE_API FGameplayAbilitySpecHandle GiveAbility(const FGameplayAbilitySpec& AbilitySpec)

Parameters

Name Type Description Default
AbilitySpec const FGameplayAbilitySpec& Specifies the ability class, level, and optional input binding to grant.

Return Type

FGameplayAbilitySpecHandle

Caveats & Gotchas

  • Must be called on the server. On a listen server / standalone this is fine at BeginPlay; in a dedicated server setup grant abilities in PossessedBy.
  • The returned FGameplayAbilitySpecHandle is the only stable reference to the granted ability — store it if you need to remove or activate it by handle later.
  • Blueprint equivalent is K2_GiveAbility, which takes a class and level directly instead of an FGameplayAbilitySpec.

Example

Grant an ability on server BeginPlay C++
void AMyCharacter::PossessedBy(AController* NewController)
{
    Super::PossessedBy(NewController);
    if (AbilitySystemComponent && HasAuthority())
    {
        FGameplayAbilitySpec Spec(UMyFireAbility::StaticClass(), 1);
        FireAbilityHandle = AbilitySystemComponent->GiveAbility(Spec);
    }
}

Version History

Introduced in: unknown

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.