How can I confirm the target data from waiting from a task in WaitTargetDataUsingActor…
- User
How can I confirm the target data from waiting from a task in WaitTargetDataUsingActor in the player controller instead of broadcasting the TargetDataReadyDelegate delegate?
- Assistant
- User
Is it better to let the target actor handle notifying the task that the target data is confirmed or is there a better way to do it?
- Assistant
It depends on your specific use case, but generally, it is better to let the target actor handle notifying the task when the target data is confirmed. This follows the principle of separating responsibilities, making the code more modular and easier to maintain. The target actor's purpose is to gather the required target data, and once it's done, it should notify the ability task.
If you use a delegate, you can easily add additional listeners in the future or even rewire the delegate to call a different event handler without modifying the target actor's code. It follows the publish-subscribe pattern, so the target actor does not need to know who specifically is using the gathered target data, making the code more flexible.
However, there may be cases when you want to have more direct control over the target data handling within the ability system, and calling the function directly can prove beneficial. But in most scenarios, it is better to use the delegate approach.
- User
How would you feel making a delegate in the player controller and when the player left clicks, the player controller checks if we are currently targeting to use an ability and it handles notifying the target actor and then the target notifies that the target data is ready?
- Assistant
This approach can be useful in certain scenarios, and it also helps to separate responsibilities and make your code more modular. To implement this, you can follow these steps:
- In your player controller class, create a new multicast delegate:
UCLASS() class YOURGAME_API AYourPlayerController : public APlayerController { GENERATED_BODY() // ... public: DECLARE_MULTICAST_DELEGATE(FOnLeftClickDelegate) FOnLeftClickDelegate OnLeftClickDelegate; void HandleLeftClick(); };- Implement the
HandleLeftClickfunction:
void AYourPlayerController::HandleLeftClick() { // Check if the player is currently targeting for an ability // ... // Notify the target actor OnLeftClickDelegate.Broadcast(); // ... } - User
What's the best to check if another ability is active that differs from the ability that I want to activate in the latest version of GAS in UE5.2
- Assistant
To check if another ability is active that differs from the ability you want to activate in GAS, you can use the
GetActiveAbilitiesWithTagsfunction from theUAbilitySystemComponent. Here's an example: - User
How do I cancel an ability from the FGameplayAbilitySpec?
- Assistant
To cancel an ability from the
FGameplayAbilitySpec, you can use theUAbilitySystemComponent::CancelAbilityfunction. Here's an example:- First, create a function in your character or player controller class that takes an
FGameplayAbilitySpecas input:
UCLASS() class YOURGAME_API AYourCharacter : public ACharacter { GENERATED_BODY() // ... public: UFUNCTION(BlueprintCallable, Category = "Abilities") void CancelAbilityFromSpec(FGameplayAbilitySpec AbilitySpec); };- Implement the function in your
.cppfile:
void AYourCharacter::CancelAbilityFromSpec(FGameplayAbilitySpec AbilitySpec) { UAbilitySystemComponent* AbilitySystemComponent = GetAbilitySystemComponent(); // You may have a different function to get the AbilitySystemComponent. if (AbilitySystemComponent) { // Calling the CancelAbility function of AbilitySystemComponent AbilitySystemComponent->CancelAbility(AbilitySpec.Ability); } } - First, create a function in your character or player controller class that takes an
- User
How do I return a spec from a method the cleanest?
- Assistant
To return an
FGameplayAbilitySpecfrom a method in a clean and efficient way, you could use a pointer toFGameplayAbilitySpecand return aTArray<FGameplayAbilitySpec*>. Here's an example:- First, create a function in your character or player controller class that returns a pointer to
FGameplayAbilitySpec:
- First, create a function in your character or player controller class that returns a pointer to