UAbilitySystemComponent::TryActivateAbility
#include "AbilitySystemComponent.h"
Access: public
Description
Attempts to activate a previously granted ability. Checks CanActivateAbility internally and handles client-side prediction if called on a client.
Signature
UE_API bool TryActivateAbility(FGameplayAbilitySpecHandle AbilityToActivate, bool bAllowRemoteActivation = true) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| AbilityToActivate | FGameplayAbilitySpecHandle | Handle returned by GiveAbility identifying which ability to activate. | — |
| bAllowRemoteActivation | bool | If true, clients will send an RPC to the server to activate the ability with prediction. | true |
Return Type
bool Caveats & Gotchas
- • A return value of true means the activation attempt was made, not that the ability finished or succeeded. ActivateAbility may still fail internally.
- • On clients with bAllowRemoteActivation=true, the ability executes speculatively on the client and the server confirms or rejects. If rejected, the client rolls back.
- • Abilities with InstancingPolicy=NonInstanced share a single CDO instance — do not store per-activation state on the ability itself.
Example
Activate an ability by stored handle on input press C++
void AMyCharacter::OnFirePressed()
{
if (AbilitySystemComponent)
{
AbilitySystemComponent->TryActivateAbility(FireAbilityHandle);
}
} Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?