void AGameplayAbilityTargetActor::BindToConfirmCancelInputs() { check(OwningAbility); UAbilitySystemComponent* ASC = OwningAbility->GetCurrentActorInfo()->AbilitySystemComponent.Get(); if (ASC) { const FGameplayAbilityActorInfo* Info = OwningAbility->GetCurrentActorInfo(); if (Info->IsLocallyControlled()) { // We have to wait for the callback from the AbilitySystemComponent. Which will always be instigated locally ASC->GenericLocalConfirmCallbacks.AddDynamic(this, &AGameplayAbilityTargetActor::ConfirmTargeting); // Tell me if the confirm input is pressed ASC->GenericLocalCancelCallbacks.AddDynamic(this, &AGameplayAbilityTargetActor::CancelTargeting); // Tell me if the cancel input is pressed } else { FGameplayAbilitySpecHandle Handle = OwningAbility->GetCurrentAbilitySpecHandle(); FPredictionKey PredKey = OwningAbility->GetCurrentActivationInfo().GetActivationPredictionKey(); GenericConfirmHandle = ASC->AbilityReplicatedEventDelegate(EAbilityGenericReplicatedEvent::GenericConfirm, Handle, PredKey ).AddUObject(this, &AGameplayAbilityTargetActor::ConfirmTargeting); GenericCancelHandle = ASC->AbilityReplicatedEventDelegate(EAbilityGenericReplicatedEvent::GenericCancel, Handle, PredKey ).AddUObject(this, &AGameplayAbilityTargetActor::CancelTargeting); if (ASC->CallReplicatedEventDelegateIfSet(EAbilityGenericReplicatedEvent::GenericConfirm, Handle, PredKey)) { return; } if (ASC->CallReplicatedEventDelegateIfSet(EAbilityGenericReplicatedEvent::GenericCancel, Handle, PredKey)) { return; } } } }
/** Outside code is saying 'stop everything and just forget about it' */ void AGameplayAbilityTargetActor::CancelTargeting() { UAbilitySystemComponent* ASC = OwningAbility->GetCurrentActorInfo()->AbilitySystemComponent.Get(); ASC->AbilityReplicatedEventDelegate(EAbilityGenericReplicatedEvent::GenericCancel, OwningAbility->GetCurrentAbilitySpecHandle(), OwningAbility->GetCurrentActivationInfo().GetActivationPredictionKey() ).Remove(GenericCancelHandle); CanceledDelegate.Broadcast(FGameplayAbilityTargetDataHandle()); Destroy(); }
void AGameplayAbilityTargetActor::ConfirmTargeting() { UAbilitySystemComponent* ASC = OwningAbility->GetCurrentActorInfo()->AbilitySystemComponent.Get(); ASC->AbilityReplicatedEventDelegate(EAbilityGenericReplicatedEvent::GenericConfirm, OwningAbility->GetCurrentAbilitySpecHandle(), OwningAbility->GetCurrentActivationInfo().GetActivationPredictionKey() ).Remove(GenericConfirmHandle); if (IsConfirmTargetingAllowed()) { ConfirmTargetingAndContinue(); if (bDestroyOnConfirmation) { Destroy(); } } }
/** Outside code is saying 'stop everything and just forget about it' */ void AGameplayAbilityTargetActor::CancelTargeting() { const FGameplayAbilityActorInfo* ActorInfo = (OwningAbility ? OwningAbility->GetCurrentActorInfo() : nullptr); UAbilitySystemComponent* ASC = (ActorInfo ? ActorInfo->AbilitySystemComponent.Get() : nullptr); if (ASC) { ASC->AbilityReplicatedEventDelegate(EAbilityGenericReplicatedEvent::GenericCancel, OwningAbility->GetCurrentAbilitySpecHandle(), OwningAbility->GetCurrentActivationInfo().GetActivationPredictionKey() ).Remove(GenericCancelHandle); } else { ABILITY_LOG(Warning, TEXT("AGameplayAbilityTargetActor::CancelTargeting called with null ASC! Actor %s"), *GetName()); } CanceledDelegate.Broadcast(FGameplayAbilityTargetDataHandle()); Destroy(); }
void AGameplayAbilityTargetActor::ConfirmTargeting() { const FGameplayAbilityActorInfo* ActorInfo = (OwningAbility ? OwningAbility->GetCurrentActorInfo() : nullptr); UAbilitySystemComponent* ASC = (ActorInfo ? ActorInfo->AbilitySystemComponent.Get() : nullptr); if (ASC) { ASC->AbilityReplicatedEventDelegate(EAbilityGenericReplicatedEvent::GenericConfirm, OwningAbility->GetCurrentAbilitySpecHandle(), OwningAbility->GetCurrentActivationInfo().GetActivationPredictionKey() ).Remove(GenericConfirmHandle); } else { ABILITY_LOG(Warning, TEXT("AGameplayAbilityTargetActor::ConfirmTargeting called with null Ability/ASC! Actor %s"), *GetName()); } if (IsConfirmTargetingAllowed()) { ConfirmTargetingAndContinue(); if (bDestroyOnConfirmation) { Destroy(); } } }