The GameplayAbilities
API allows you to associate a set of attributes, that is, UAttributeSet
, to an Actor. UAttributeSet
describes properties appropriate for that Actor's in-game attributes, such as Hp
, Mana
, Speed
, Armor
, AttackDamage
, and so on. You can either define a single game-wide set of attributes common to all Actors, or several different sets of attributes appropriate for the different classes of actors.
AbilitySystemComponent
is the first thing you will need to add to your actors to equip them to use GameAbilities API and UAttributeSet
s. To define your custom UAttributeSet
, you will simply derive from the UAttributeSet
base class and extend the base class with your own series of UPROPERTY
members. After that, you must register your custom AttributeSet
with your Actor
class' AbilitySystemComponent
.
GameplayAbilities
API in your ProjectName.Build.cs
file.UAttributeSet
class and deck the class out with a set of UPROPERTY
that you want each Actor to have in their property set. For example, you might want to declare your UAttributeSet
derivate class similar to the following piece of code:#include "Runtime/GameplayAbilities/Public/AttributeSet.h" #include "GameUnitAttributeSet.generated.h" UCLASS(Blueprintable, BlueprintType) class CHAPTER12_API UGameUnitAttributeSet : public UAttributeSet { GENERATED_BODY() public: UGameUnitAttributeSet( const FObjectInitializer& PCIP ); UPROPERTY( EditAnywhere, BlueprintReadWrite, Category = GameUnitAttributes ) float Hp; UPROPERTY( EditAnywhere, BlueprintReadWrite, Category = GameUnitAttributes ) float Mana; UPROPERTY( EditAnywhere, BlueprintReadWrite, Category = GameUnitAttributes ) float Speed; };
GameUnitAttributeSet
with your AbilitySystemComponent
inside your Actor
class by calling the following code:AbilitySystemComponent->InitStats( UGameUnitAttributeSet::StaticClass(), NULL );
You can put this call somewhere in PostInitializeComponents()
, or in code that is called later than that.
UAttributeSet
, you can move on with the next recipe and apply GameplayEffect
to some of the elements in the attribute set.Actor
class object implements IAbilitySystemInterface
by deriving from it. This is extremely important as the UAbilitySet
object will attempt a cast to IAbilitySystemInterface
to call GetAbilitySystemComponent()
on it at various places in the code.
UAttributeSets
simply allow you to enumerate and define attributes of different actors. GameplayEffects
will be your means to make changes to the attributes of a specific actor.
You can code in definitions of GameplayEffects
, which will be things that act on the AbilitySystemComponent's AttributeSet
collections. You can also write GameplayTasks
for generic functions that run at specific time or events, or even in response to tag addition (GameplayTagResponseTable.cpp
). You can define GameplayTags
to modify GameplayAbility behavior as well as select and match gameplay units during play.
18.220.106.241