Download

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())
            {
                InternalTryActivateAbilityFailureTags.AddTag(NetworkFailTag);
                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… :frowning:

Any ideas ???

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);
    }
}


allso i overridet PossessedBy so after possession informations refreshed:



void ACharacterRoot::PossessedBy(AController * NewController)
{
    Super::PossessedBy(NewController);

    AbilitySystemComponentas->RefreshAbilityActorInfo();
}


After some research, before trying to activate ability i added



AbilitySystemComponentas->CanPredict()


And i get FALSE…

*bool CanPredict()
Do we have a valid prediction key to do more predictive actions with

So something frong with prediction key… propably…*

well… i dont know what to do :frowning: 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:


  FPredictionKey()
  : 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() ???

I found solution here:
https://answers.unrealengine.com/questions/889933/view.html