Download

GamePlayAbility crash in multiplayer

Hey guys,
I have understood how GamePlayAbilities work,
but an only thing is unclear is how to activate them in multiplayer environment? Right now, every time when I try to activate it from Client - I get the crash. As far as I understand, I need to activate it on server, but how?

here is my code:



//GIVE ABILITY ONLY AT SERVER FOR BOTH CLIENTS
**void** ATestCharacter::BeginPlay()

{

    Super::BeginPlay();

**if**(AbilitySystem)

    {

**if** (HasAuthority() && ThrowAbility)

        {

            AbilitySystem->GiveAbility(FGameplayAbilitySpec(ThrowAbility.GetDefaultObject(), 1, 0));

        }

        AbilitySystem->InitAbilityActorInfo(**this**, **this**);

    }

}


//when I receive input - I will activate an ability
PlayerInputComponent->BindAction("ThrowItem", IE_Pressed, **this**, &ATestCharacter::Server_Throw);

//THIS CODE WILL CAUSE CRASH ON CLIENT ONLY, ON SERVER ITS OK
**void** ATestCharacter::Server_Throw()

{

**if**(HasAuthority())

    {

        AbilitySystem -> TryActivateAbilityByClass(ThrowAbility, **true**);

    }

}


Why AbilitySystem -> TryActivateAbilityByClass(ThrowAbility, true); is causing crash on clients? what is wrong?

The client Has no authority, he will just skip the whole Server_Throw method.
Then I can’t tell why it’s crashing…

I have found that on the Client my AbilitySystemComponent is always NULL, this was the reason of crashes. However, if I call method from Server,Reliable - component is still null…