-
Notifications
You must be signed in to change notification settings - Fork 9
Target Selection
Important
Target Selection is used to find nearby Graspable Components which then give us their abilities
Their abilities define what happens when we interact with them
This is performed only on Authority (Server-only if multiplayer)
A Graspable Component is any component that we can interact with. They contain UGraspData that contains a gameplay ability.
We scan for these using UGraspScanTask which runs from the UGraspScanAbility that we assign when we call UGraspComponent::InitializeGrasp().
If you followed the tutorial, you likely assigned a data asset to the DefaultTargetingPresets on the UGraspComponent.
This targeting preset defines how we look for graspable components to grant their ability to our AbilitySystemComponent for our Pawn to utilize.
It is likely unnecessary, but you do have the option of adding additional targeting channels by adding more targeting presets to the DefaultTargetingPresets array. This could be used to locate high priority interactables that are very time sensitive, to ensure their ability is granted in time for prediction to occur reliably.
However, the vast majority of games will not require this. As a general rule, you should not use this until you find that you need to use this.
Multiple targeting presets means you're running multiple traces every frame instead of only one, so whether that cost is worthwhile or not is a late-game optimization.
You can optionally subclass UGraspComponent and override GetTargetingPresets() to return anything other than the DefaultTargetingPresets.
Note
The goal is to have the ability be given, and then replicated, before we reach interaction range. This is because giving an ability is not net predicted. You will want to adjust these values to suit your game's movement and also the general range of latency you intend to support, but for most use-cases the defaults will suit
The GraspTargeting data assigned to your Grasp component's DefaultTargetingPreset can be visualized with p.Grasp.Selection.Debug 1
Open up your preset. You can change the Grasp Selection Shape options to adjust this shape.
Anything outside of this shape will cause us to lose it's ability.
However, we do not grant anything inside of this shape until we reach the % defined by the GraspData's NormalizedGrantAbilityDistance. This prevents us from rapidly giving/clearing abilities as we repeatedly re-enter the scanning range, which has a cost associated.
Optionally you can enable GrantAbilityDistance2D if you want to ignore the vertical height for give ability checks.
You can visualize give ability with p.Grasp.GiveAbility.Debug 1. While adjusting these properties you should have both debugging CVars enabled.
