Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdc0d3df

Browse files
committed
Added TargetActor to EffectContext
- New ObjectPtr to any const Actor* to EffectContext, NetSerialized- Added convenience method to access/set TargetActor (see UCustomAbilitySystemBlueprintLibrary)- ASC::ApplyGameplayEffectSpecToTarget will set the target automatically
1 parent6fa1730 commitdc0d3df

File tree

7 files changed

+78
-9
lines changed

7 files changed

+78
-9
lines changed

‎Source/GAS_Example/AbilitySystem/AbilitySystemComponent/CustomAbilitySystemComponent.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include"CustomAbilitySystemComponent.h"
44
#include"GAS_Example/AbilitySystem/AttributeSets/LevelAttributeSet.h"
55
#include"GAS_Example/AbilitySystem/Data/NativeGameplayTags.h"
6+
#include"GAS_Example/AbilitySystem/FunctionLibrary/CustomAbilitySystemBlueprintLibrary.h"
67
#include"GAS_Example/Characters/CharacterBase.h"
78

89

@@ -175,6 +176,16 @@ PRAGMA_ENABLE_DEPRECATION_WARNINGS
175176
}
176177
}
177178

179+
FActiveGameplayEffectHandleUCustomAbilitySystemComponent::ApplyGameplayEffectSpecToTarget(const FGameplayEffectSpec& GameplayEffect, UAbilitySystemComponent* Target, FPredictionKey PredictionKey)
180+
{
181+
if (Target->GetOwner())
182+
{
183+
UCustomAbilitySystemBlueprintLibrary::SetTargetOnGameplayEffectContextFromSpec(const_cast<FGameplayEffectSpec&>(GameplayEffect), Target->GetOwner());
184+
}
185+
186+
returnSuper::ApplyGameplayEffectSpecToTarget(GameplayEffect, Target, PredictionKey);
187+
}
188+
178189
voidUCustomAbilitySystemComponent::InitializeAbilitySystemData(const FAbilitySystemInitializationData& InitializationData, AActor* InOwningActor, AActor* InAvatarActor)
179190
{
180191
if (AbilitySystemDataInitialized)

‎Source/GAS_Example/AbilitySystem/AbilitySystemComponent/CustomAbilitySystemComponent.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ class GAS_EXAMPLE_API UCustomAbilitySystemComponent : public UAbilitySystemCompo
6767

6868
virtualvoidAbilitySpecInputPressed(FGameplayAbilitySpec& Spec)override;
6969
virtualvoidAbilitySpecInputReleased(FGameplayAbilitySpec& Spec)override;
70+
71+
virtual FActiveGameplayEffectHandleApplyGameplayEffectSpecToTarget(const FGameplayEffectSpec& GameplayEffect, UAbilitySystemComponent* Target, FPredictionKey PredictionKey =FPredictionKey())override;
7072
};

‎Source/GAS_Example/AbilitySystem/Data/AbilitySystemData.cpp‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ bool FCustomGameplayEffectContext::NetSerialize(FArchive& Ar, class UPackageMap*
1111
enum RepFlag
1212
{
1313
REP_CustomContextData,
14+
REP_TargetActor,
1415
REP_MAX
1516
};
1617

@@ -21,13 +22,21 @@ bool FCustomGameplayEffectContext::NetSerialize(FArchive& Ar, class UPackageMap*
2122
{
2223
RepBits |=1 << REP_CustomContextData;
2324
}
25+
26+
if (TargetActor)
27+
{
28+
RepBits |=1 << REP_TargetActor;
29+
}
2430
}
2531

2632
Ar.SerializeBits(&RepBits, REP_MAX);
2733
if (RepBits & (1 << REP_CustomContextData))
2834
{
2935
bCombinedSuccess &= SafeNetSerializeTArray_WithNetSerialize<31>(Ar, CustomContextData, Map);
30-
36+
}
37+
if (RepBits & (1 << REP_TargetActor))
38+
{
39+
Ar << TargetActor;
3140
}
3241

3342
return bCombinedSuccess;

‎Source/GAS_Example/AbilitySystem/Data/AbilitySystemData.h‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,22 @@ struct FCustomGameplayEffectContext : public FGameplayEffectContext
116116
protected:
117117
UPROPERTY(EditAnywhere, meta=(ExcludeBaseStruct))
118118
TArray<FInstancedStruct> CustomContextData{};
119+
120+
UPROPERTY(EditAnywhere, meta=(ExcludeBaseStruct))
121+
TObjectPtr<const AActor> TargetActor;
119122

120123
public:
121124

125+
voidSetTargetActor(const AActor* InTargetActor)
126+
{
127+
TargetActor = InTargetActor;
128+
}
129+
130+
const AActor*GetTargetActor()const
131+
{
132+
return TargetActor.Get();
133+
}
134+
122135
virtualboolNetSerialize(FArchive& Ar, UPackageMap* Map,bool& bOutSuccess)override;
123136

124137
template<typename T>
@@ -145,9 +158,6 @@ struct FCustomGameplayEffectContext : public FGameplayEffectContext
145158
CustomContextData.Add(MoveTemp(InstancedStruct));
146159
}
147160

148-
// UPROPERTY(EditAnywhere, BlueprintReadWrite)
149-
// FCustomContextData_TurnBaseEffect TurnBaseEffectData{};
150-
151161
/** Returns the actual struct used for serialization, subclasses must override this!*/
152162
virtual UScriptStruct*GetScriptStruct()constoverride
153163
{
@@ -160,6 +170,9 @@ struct FCustomGameplayEffectContext : public FGameplayEffectContext
160170
FCustomGameplayEffectContext* NewContext =newFCustomGameplayEffectContext();
161171
*NewContext = *this;
162172
NewContext->AddActors(Actors);
173+
174+
NewContext->TargetActor = TargetActor;
175+
163176
if (GetHitResult())
164177
{
165178
// Does a deep copy of the hit result

‎Source/GAS_Example/AbilitySystem/FunctionLibrary/CustomAbilitySystemBlueprintLibrary.cpp‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,33 @@ float UCustomAbilitySystemBlueprintLibrary::GetValueAtLevel(const FScalableFloat
4646
return ScalableFloat.GetValueAtLevel(Level, &ContextString);
4747
}
4848

49+
voidUCustomAbilitySystemBlueprintLibrary::SetTargetOnGameplayEffectContext(FGameplayEffectContextHandle& ContextHandle,const AActor* TargetActor)
50+
{
51+
if (FCustomGameplayEffectContext*const EffectContext =static_cast<FCustomGameplayEffectContext*>(ContextHandle.Get()))
52+
{
53+
EffectContext->SetTargetActor(TargetActor);
54+
}
55+
}
56+
57+
voidUCustomAbilitySystemBlueprintLibrary::SetTargetOnGameplayEffectContextFromSpec(FGameplayEffectSpec& EffectSpec,const AActor* TargetActor)
58+
{
59+
SetTargetOnGameplayEffectContext(const_cast<FGameplayEffectContextHandle&>(EffectSpec.GetEffectContext()), TargetActor);
60+
}
61+
62+
const AActor*UCustomAbilitySystemBlueprintLibrary::GetTargetActorFromGameplayEffectContext(const FGameplayEffectContextHandle& ContextHandle)
63+
{
64+
if (const FCustomGameplayEffectContext*const EffectContext =static_cast<const FCustomGameplayEffectContext*>(ContextHandle.Get()))
65+
{
66+
return EffectContext->GetTargetActor();
67+
}
68+
returnnullptr;
69+
}
70+
71+
const AActor*UCustomAbilitySystemBlueprintLibrary::GetTargetActorFromGameplayEffectSpec(const FGameplayEffectSpec& EffectSpec)
72+
{
73+
returnGetTargetActorFromGameplayEffectContext(EffectSpec.GetEffectContext());
74+
}
75+
4976
voidUCustomAbilitySystemBlueprintLibrary::GetAttributeValue(const UAbilitySystemComponent*const AbilitySystemComponent,const FGameplayAttribute& Attribute,const EAttributeSearchType SearchType, OUTfloat& ReturnValue)
5077
{
5178
ReturnValue = -1.0f;

‎Source/GAS_Example/AbilitySystem/FunctionLibrary/CustomAbilitySystemBlueprintLibrary.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ class GAS_EXAMPLE_API UCustomAbilitySystemBlueprintLibrary : public UAbilitySyst
3737

3838
UFUNCTION(BlueprintPure, Category ="Ability System", meta=(AutoCreateRefTerm="ContextString"))
3939
staticfloatGetValueAtLevel(const FScalableFloat& ScalableFloat,constfloat Level =0.f,const FString& ContextString ="");
40+
41+
UFUNCTION(BlueprintCallable, Category ="Ability System", meta=(AutoCreateRefTerm="ContextString"))
42+
staticvoidSetTargetOnGameplayEffectContext(FGameplayEffectContextHandle& ContextHandle,const AActor* TargetActor);
43+
44+
UFUNCTION(BlueprintCallable, Category ="Ability System", meta=(AutoCreateRefTerm="ContextString"))
45+
staticvoidSetTargetOnGameplayEffectContextFromSpec(FGameplayEffectSpec& EffectSpec,const AActor* TargetActor);
46+
47+
UFUNCTION(BlueprintPure, Category ="Ability System", meta=(AutoCreateRefTerm="ContextString"))
48+
staticconst AActor*GetTargetActorFromGameplayEffectContext(const FGameplayEffectContextHandle& ContextHandle);
49+
50+
UFUNCTION(BlueprintPure, Category ="Ability System", meta=(AutoCreateRefTerm="ContextString"))
51+
staticconst AActor*GetTargetActorFromGameplayEffectSpec(const FGameplayEffectSpec& EffectSpec);
4052
private:
4153

4254
staticvoidGetAttributeValue(const UAbilitySystemComponent*const AbilitySystemComponent,const FGameplayAttribute& Attribute,const EAttributeSearchType SearchType, OUTfloat& ReturnValue);

‎Source/GAS_Example/AbilitySystem/FunctionLibrary/TurnBasedAbilitySystemBlueprintLibrary.cpp‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ FCustomContextData_TurnBaseEffect UTurnBasedAbilitySystemBlueprintLibrary::GetTu
126126
{
127127
returnFCustomContextData_TurnBaseEffect();
128128
}
129-
130-
// if (EffectContext->GetScriptStruct()->IsChildOf(FCustomGameplayEffectContext::StaticStruct()))
131-
// {
132-
// return FCustomContextData_TurnBaseEffect();
133-
// }
134129

135130
for (constauto& ContextData : EffectContext->GetAllCustomContextData())
136131
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp