Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Gameplay Abilities: TryActivateAbilityByClass results error

So.. here is the problem:

I have dedicated server.

  1. Server creates actor

  2. Server gives ability to actor

  3. Player connects and possesses actor.

  4. Trying activate ability.

  5. Getting error:

Warning: Can't activate LocalOnly or LocalPredicted ability Default__GA_BasicMeleeAtack_C when not local! Net Execution Policy is 0.

and ability doesn't work.

(btw. dedicated server doesn't have sessions set up, client connects by IP)

After some digging i found:

         if (Ability->GetNetExecutionPolicy() == EGameplayAbilityNetExecutionPolicy::LocalOnly || (Ability->GetNetExecutionPolicy() == EGameplayAbilityNetExecutionPolicy::LocalPredicted && !InPredictionKey.IsValidKey()))
             // If we have a valid prediction key, the ability was started on the local client so it's okay
             ABILITY_LOG(Warning, TEXT("Can't activate LocalOnly or LocalPredicted ability %s when not local! Net Execution Policy is %d. "), *Ability->GetName(), (int32)Ability->GetNetExecutionPolicy());
             if (NetworkFailTag.IsValid())
                 NotifyAbilityFailed(Handle, Ability, InternalTryActivateAbilityFailureTags);
             return false;

Net Execution Policy is Local Predicted.

So i think something wrong with PredictionKey... and my skills not enough to find out whats wrong..

so i added to plugin this:

 ABILITY_LOG(Warning, TEXT("InPredictionKey = %s"), (InPredictionKey.IsValidKey() ? TEXT("True") : TEXT("False")));

and getting false.

So how to fix this key stuff?

This is how ability is acquired:

 void ACharacterRoot::XAquireAbility(TSubclassOf<UGameplayAbility> wAbilityToAquire)
     if (AbilitySystemComponentas)
         if (HasAuthority() && wAbilityToAquire)
             AbilitySystemComponentas->GiveAbility(FGameplayAbilitySpec(wAbilityToAquire, 1, 0));
         AbilitySystemComponentas->InitAbilityActorInfo(this, this);

Also i overridet PossessedBy so after possession information is refreshed:

 void ACharacterRoot::PossessedBy(AController * NewController)
     if (AbilitySystemComponentas)

Product Version: UE 4.21
more ▼

asked Apr 15 '19 at 10:35 AM in C++ Programming

avatar image

Unit Seven
1 1 1

avatar image Unit Seven Apr 17 '19 at 09:08 AM

well... i dont know what to do :( so i'm messing around...

when i'm using TryActivateAbilityByClass then in chain reaction this function is called:

     /** Attempts to activate the given ability, will only work if called from the correct client/server context */
     bool InternalTryActivateAbility(FGameplayAbilitySpecHandle AbilityToActivate, FPredictionKey InPredictionKey = FPredictionKey(), UGameplayAbility ** OutInstancedAbility = nullptr, FOnGameplayAbilityEnded::FDelegate* OnGameplayAbilityEndedDelegate = nullptr, const FGameplayEventData* TriggerEventData = nullptr);

So... InternalTryActivateAbility have FPredictionKey InPredictionKey = FPredictionKey() with default value... and by default it getting not valid key...

so in fileGameplayPrediction.h i writed line with log:

     : Current(0), Base(0), PredictiveConnection(nullptr), bIsStale(false), bIsServerInitiated(false)
             UE_LOG(LogTemp, Display, TEXT(" STEP D5. FPredictionKey() !!!!!!!!!!!!!!!!!!!"));

but what is strange... now i'm getting log full message. even if i comment:

     // Construc component
     //AbilitySystemComponentas = CreateDefaultSubobject<UAbilitySystemComponent>("AbilitySystemComponentas");

who the hell generating FPredictionKey() ????link text

unitfive-2.log (175.0 kB)
avatar image Firefly74 Apr 17 '19 at 04:19 PM

Could you share the advanced category properties on you blueprint ?

right now i suppose it's a local one, and you try to call "Trying activate ability" from the server, you should try to activate it on the client side ( or change the settings) ability system take care of activating it on the server side

Ability system is not easy to understand and take in hand, no much ressources on that

avatar image Unit Seven Apr 18 '19 at 06:39 AM

Well there mine blueprints...

A'm activating ability with HasAuthority so it is called on client... i think... BTW.. before line which prints out error i added another to log InPredictionKey.IsValidKey() and i'm getting false... So i think mine local client dont generate keys... or local client thinks that it is server...

ability.png (304.7 kB)
activation.png (363.9 kB)
avatar image Firefly74 Apr 18 '19 at 09:52 AM

But then you should put local only as your ability is not replicated

avatar image Unit Seven Apr 18 '19 at 10:43 AM

I changed net execution policy to LocalOnly resultat:

[ 66]LogAbilitySystem: Warning: Can't activate LocalOnly or LocalPredicted ability Default__GA_BasicMeleeAtack_C when not local! Net Execution Policy is 1.


I even added check for IsDedicated server. Well i'm getting false... So i'm trying to run on client locally...

[1]: /storage/temp/274585-ability.png

ability.png (297.3 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first


in guides i red that you need to refresh actor info after possession and override PossessedBy function... But problem is that PossessedBy is called only on server... So i tried refresh actor info before activate ability on client and ability STARTED to work. Last thing for me.. decide where exactly to put RefreshActorInfo so it will be called on server and on client...

more ▼

answered Apr 19 '19 at 08:10 AM

avatar image

Unit Seven
1 1 1

avatar image Firefly74 Apr 19 '19 at 10:07 AM

on the controler, override the method on playerControler " virtual void ClientRestart_Implementation(class APawn* NewPawn) override;" ( and get pawn + cast to your pawn class and call it from there )

avatar image Unit Seven Apr 23 '19 at 07:42 AM

Well its working... I've done what you told me...

Thank you for your time... and help..

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Found it ! you call AbilitySystem->InitAbilityActorInfo(this, this); only on the server, put it in begin play !

because your client has no actor infos, so when it try to look if it's a local player, it's can't know ( so it answer false )

more ▼

answered Apr 18 '19 at 11:07 AM

avatar image

1.4k 14 17 31

avatar image Unit Seven Apr 18 '19 at 12:22 PM

AbilitySystem->InitAbilityActorInfo(this, this) is called in function ACharacterRoot::XAquireAbility

And function XAquireAbility is called from BeginPlay in blueprint...

and PossessedBy is overriden and when controller possesses actor with ability, AbilitySystemComponentas->RefreshAbilityActorInfo() is called.

[1]: /storage/temp/274586-aquareability.png

aquareability.png (148.6 kB)
avatar image Firefly74 Apr 18 '19 at 12:43 PM

just before the line you posted if (Ability->GetNetExecutionPolicy() == EGameplayAbilityNetExecutionPolicy::LocalOnly || (Ability->GetNetExecutionPolicy() == EGameplayAbilityNetExecutionPolicy::LocalPredicted && !InPredictionKey.IsValidKey()))

the is a line

 bool bIsLocal = AbilityActorInfo->IsLocallyControlled();

it currently return false ( but should return true ) but a breakpoint and check what's happening in there also put a breakpoint on you blueprint when you try to activate ability and check if it's on server or client !

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question