Do batch grant ability sets

master
MostExcellent 2024-10-22 12:11:31 -07:00
parent 54e9efd1e0
commit c68562eca6
2 changed files with 30 additions and 0 deletions

View File

@ -6,6 +6,8 @@
#include "AbilitySystemComponent.h"
#include "AbilitySystemGlobals.h"
#include "GameplayAbilitySpec.h"
#include "Logging.h"
#include "VRGASTypes.h"
#include "Abilities/GameplayAbility.h"
void UVRGASUtils::BatchGrantAbilities(const TArray<TSubclassOf<UGameplayAbility>>& InAbilitiesToGrant, UAbilitySystemComponent* InAbilitySystemComponent, int32 ApplyLevel, bool bDebugLog)
@ -29,6 +31,29 @@ void UVRGASUtils::BatchGrantAbilities(const TArray<TSubclassOf<UGameplayAbility>
}
}
void UVRGASUtils::BatchGrantAbilitySets(const TArray<FVRAbilitySet>& AbilitySetsToGrant, UAbilitySystemComponent* InAbilitySystemComponent, bool bDebugLog)
{
if (AbilitySetsToGrant.IsEmpty()) return;
for (const FVRAbilitySet& AbilitySet : AbilitySetsToGrant)
{
if (!AbilitySet.IsValid()) continue;
FGameplayAbilitySpec AbilitySpec(AbilitySet.AbilityClass);
AbilitySpec.SourceObject = InAbilitySystemComponent->GetAvatarActor();
AbilitySpec.Level = AbilitySet.AbilityLevel;
if (AbilitySet.IsValidInput())
AbilitySpec.DynamicAbilityTags.AddTag(AbilitySet.InputTag);
InAbilitySystemComponent->GiveAbility(AbilitySpec);
if (bDebugLog)
{
UE_LOG(VRGAS_Log, Log, TEXT("Successfully given ability %s from Ability Set"), *AbilitySpec.Handle.ToString())
}
}
}
bool UVRGASUtils::ApplyEffectToTarget(AActor* Target, TSubclassOf<UGameplayEffect> GameplayEffectClass, UObject* SourceObject, float Level)
{
// Get the Ability System Component of the target

View File

@ -6,6 +6,7 @@
#include "Kismet/BlueprintFunctionLibrary.h"
#include "VRGASUtils.generated.h"
struct FVRAbilitySet;
class UGameplayAbility;
class UGameplayEffect;
class UAbilitySystemComponent;
@ -24,6 +25,10 @@ public:
UAbilitySystemComponent* InAbilitySystemComponent,
int32 ApplyLevel, bool bDebugLog = false);
UFUNCTION(BlueprintCallable, Category = "Utils|Ability System")
static void BatchGrantAbilitySets(const TArray<FVRAbilitySet>& AbilitySetsToGrant,
UAbilitySystemComponent* InAbilitySystemComponent, bool bDebugLog = false);
UFUNCTION(BlueprintCallable, Category = "Utils|Ability System")
static bool ApplyEffectToTarget(AActor* Target, TSubclassOf<UGameplayEffect> GameplayEffectClass, UObject* SourceObject, float Level = 1.f);