Attributes
Attributes are values that define stats for your GameplayAbilitySystemComponent
e.g. health, stamina, speed.
SimpleGAS gives you two types of attributes to work with: Float Attributes for simple numbers and Struct Attributes for more complex data.
Float Attributes
Attribute Name
: A friendly label to help you identify the attribute in the editorAttribute Tag
: A unique gameplay tag that identifies this attributeBase Value
: A “permanent” value that represents the inherent statCurrent Value
: The actual value used during gameplay that can be modified temporarily- For example, a character might have a Base Strength of 10, but a Current Strength of 15 due to a temporary buff. When the buff wears off, the Current Strength goes back to the Base Value.
Value Limits
: Optional min/max boundaries for the attribute
Tip: You can choose to only use Current Value if that’s all you need - the Base Value is there in case you want that extra layer of “permanent vs temporary” changes.
Here’s what a Float Attribute looks like in the editor:
Struct Attributes
Sometimes a simple number isn’t enough. That’s where Struct Attributes come in - they can store complex data like inventory items, skill trees, or any custom struct you create.
Struct Attributes have:
Attribute Name
: A friendly label to help you identify the attribute in the editorAttribute Tag
: A unique gameplay tag that identifies this attributeStructType
: The struct type this attribute representsStructAttributeHandler
: On optional handler object class reference that you can use to send fine grained events when the attribute changes
Here’s an example of a Struct Attribute in the editor:
How To Modify Attributes
Float Attributes
-
Calling the
SetFloatAttribute
function on theGamplayAbilitySystemComponent
that owns the attribute:
-
Using an
Attribute Modifier
:
Struct Attributes
-
Calling the
SetStructAttribute
function on theGamplayAbilitySystemComponent
that owns the attribute:
-
Using an
Attribute Modifier
:
Inside the struct modification function:
How To Listen For Changes
When an attribute changes, SimpleGAS automatically sends an event through the Simple Event Subsystem so other systems (like your UI) can react to the change.
You can find a list of the available events on the Event Reference page.
Float Attributes
Struct Attributes
Struct Attribute Handlers
Struct attributes are a bit different from float attributes when it comes to the event that gets sent.
When a struct attribute changes, the entire struct is replaced. This presents a problem for when we are modifying the struct. Even though we know which struct members changed there is no easy way to automatically send an event for each member that changed.
To get around this, you can create a StructAttributeHandler
class to send fine-grained events when the attribute changes.
To create a struct attribute handler, create a new blueprint class that inherits from UStructAttributeHandler
. This class only has a single function to implement called GetModificationEvents
. It takes as input two FInstancedStruct
parameters (the old struct and the new one) and returns an FGameplayTagContainer
with the tags representing the members of the struct that changed:
The GetModificationEvents
function will be called whenever the struct attribute changes and you can use it to determine which fields in the struct changed.
You can then listen for the corresponding struct member events. If no StructAttributeHandler
is set on the struct attribute definition, you’ll still receive an event when the struct changes, but it won’t have any ModificationTags
in it.
Attribute Sets
If you find yourself creating the same attributes for different characters, Attribute Sets can help. They’re reusable collections of attributes that you can add to any ability component.
To create an Attribute Set:
- Right-click in the content browser
- Choose Create → Data Asset
- Select “Attribute Set” as the class
- Add your attributes to the set
Now you can add this set to any ability component instead of manually recreating the same attributes.