tranek / GASDocumentation

My understanding of Unreal Engine 5's GameplayAbilitySystem plugin with a simple multiplayer sample project.
MIT License
4.26k stars 789 forks source link

Suggestion for section 4.11.2 (custom target actor confirmation type) #119

Open jign opened 11 months ago

jign commented 11 months ago

On confirming TargetActors using EGameplayTargetingConfirmation::Custom, the docs suggest using UGameplayAbility::ConfirmTaskByInstanceName

Currently it reads

The GameplayTargeting Ability is responsible for deciding when the targeting data is ready by calling UGameplayAbility::ConfirmTaskByInstanceName(). The TargetActor will also respond to UGameplayAbility::CancelTaskByInstanceName() to cancel targeting.

But sometimes you don't want the ability to tell the target actor that it's ready. For example, you may want to spawn a hitbox for a few seconds and return the first successful hit as target data. Then, the ability couldn't possibly know when to confirm the task, since the ability doesn't know about the internals of the target actor (and shouldn't).

But this function goes through an external confirm pipeline. So in this case where the target actor itself is in charge of filtering and selecting the target data, semantically it seems that using this method is a bit like telling somebody else to tell me to do something.

In my custom target actor, when I have what I want I just call the exec pin directly via the automatically bound TargetActor delegates.

const auto TargetDataHandle{MakeTargetData(Hit)};
TargetDataReadyDelegate.Broadcast(TargetDataHandle);

See AbilityTask_WaitTargetData line 145 to see where the task is binding these delegates

So my suggestion is just adding an extra line to the Custom and CustomMulti types, such as

The GameplayTargeting Ability is responsible for deciding when the targeting data is ready by calling UGameplayAbility::ConfirmTaskByInstanceName(). The TargetActor will also respond to UGameplayAbility::CancelTaskByInstanceName() to cancel targeting. If the TargetActor is the one deciding when the data is ready, call the delegate directly via TargetDataReadyDelegate.Broadcast(Data) or alternatively CanceledDelegate.Broadcast