Hi all
I’ve tried to add GAS and multiplayer to my game and until now everything was working. But now I’m stuck with my “attack ability”. My played montage is not visible in every case:
CLIENT TO HOST: Works - the montage is visible on the client and on the host.
CLIENT TO CLIENT: Does not work comletely - only visible on the owned client and on the host.
HOST TO CLIENT: Does not work - only visible on the host.
Here is my code:
UCLASS()
class PROJECTTOPDOWN_API UAttackGameplayAbility : public UProjectGameplayAbility
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable)
void Attack();
protected:
virtual void ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData) override;
ABaseCharacter* BaseCharacter;
UFUNCTION(NetMulticast,Reliable)
void PlayMontageMulticast();
UFUNCTION(Server,Reliable,WithValidation)
void PlayMontageServer();
UFUNCTION()
void PlayAttackMontage();
};
.cpp
void UAttackGameplayAbility::Attack()
{
if (!BaseCharacter)
{
BaseCharacter = Cast<ABaseCharacter>(CurrentActorInfo->AvatarActor.Get());
}
if (BaseCharacter->IsUnoccupied())
{
if (HasAuthority(&CurrentActivationInfo))
{
PlayMontageMulticast();
}
else
{
PlayMontageServer();
}
BaseCharacter->GetEquippedWeapon()->Attack(true,true);
}
}
void UAttackGameplayAbility::ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo,
const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData)
{
Super::ActivateAbility(Handle, ActorInfo, ActivationInfo, TriggerEventData);
}
void UAttackGameplayAbility::PlayAttackMontage()
{
BaseCharacter->GetAnimInstance()->Montage_Play(BaseCharacter->GetEquippedWeapon()->GetAnimShootMontage());
}
void UAttackGameplayAbility::PlayMontageServer_Implementation()
{
PlayMontageMulticast();
}
bool UAttackGameplayAbility::PlayMontageServer_Validate()
{
return true;
}
void UAttackGameplayAbility::PlayMontageMulticast_Implementation()
{
PlayAttackMontage();
}
What am I doing wrong? (I also replicate the BaseCharacter class as well as the EquippedWeaponClass) And the function will be called in every case (The niagara effect which I call with the “BaseCharacter->GetEquippedWeapon()->Attack(true,true)” function is always visible on the host an on the clients)
Thanks!
Best regards