Overview
GGA also has another code module called GenericGameplayAttribute, which is responsible for expanding the GameplayAttribute part of the GAS system and includes some built-in GameplayAttributes, also explained how the AttributeSet code generation works.
This module is very lightweight.
Attribute and Tag Mapping
GAS very much embraces GameplayTags, however, GameplayAttribute is not driven by GameplayTag, for this reason, GGA provides an optional mapping of GameplayAttribute to GameplayTag.
You can get Attribute through Tag and you can get Tag through Attribute.
You can also register Attribute to a Tag at runtime (this operation is global).
Built-in Attributes
The GenericGameplayAttributes module comes with three commonly used attribute sets, AS_Health, AS_Mana, and AS_Stamina.
You can use it or not. It is abstract enough and is automatically generated (see below).
How to design an AttributeSet
If you refer to various examples and tutorials on the web, you will find that people are used to using one AttributeSet to define all the attributes used in the game, and they will write a lot of gameplay logic in the AttributeSet, which I don't think is desirable.
Instead, I think AttributeSet should be divided according to the function in the game, and just play the role of data definition. It doesn't need to contain gameplay logic, and only needs to be processed externally according to the logic of attribute changes.
Assuming your game requires two attributes, Health, and Stamina, you should define two AttributeSets.
AS_Health(attributes related to health)
AS_Stamina(attributes related to stamina)
The advantages of doing this are:
- In multiplayer games, different characters may need different attributes. In order to avoid a lot of network replication costs, you should only give the set of attributes needed by the characters that need it.
- At the same time, this modular design can go far in the future. (For example, if you use GameFeature, and one of your subFeatures defines its dedicated set of attributes)
Don't abuse GameplayAttributes. Here's a great post that teaches you how to use a small number of attributes and accomplish complex tasks.
About Code Generation
GGA provides an code generation funationality that allows you to generate C++ AttributeSet codes.
Even for C++ users, adding new attributes can be a very tedious process that requires a lot of code to be written by hand.
In order to use code generation, you must install visual studio on windows or XCode on your mac by following official documentation, and then convert your project into a C++ project.
Current generation workflow
- Use a C++ project with Visual Studio on Windows or Xcode on Mac. Check allowed output paths in the project's GGA AttributeSet Generator settings.
- Create an AttributeSet Definition. Select a Runtime target module, output layout and allowed subpath, then set the class, parent and attributes. Configure replication, Blueprint accessors, Gameplay Tags, minimum values and related maximum attributes as needed.
- Review the output paths and dependency hints, validate the definition, then generate. Regeneration overwrites existing output and creates a backup under the project's Saved directory; check any manual changes first.
- Add the indicated dependencies to the target module's
.Build.csand compile the project. The generator produces a C++ AttributeSet and optional Blueprint accessor functions; it does not automatically create Blueprint assets.
The screenshots and code below are retained as historical examples; use the current editor and generated output as the reference.
Code Generation Guide
GGA provides code generation functionality to help you generate C++ AttributeSet code. Even for C++ users, adding new attributes is a very tedious process, requiring a lot of boilerplate code to be written manually. To use the code generation feature, you need to install Visual Studio on Windows or Xcode on Mac (please refer to the official documentation) and convert your project into a code project.
Steps to add a new attribute set:
- Create a new attribute set definition asset: Right-click in the blank area of ​​the project browser -> GenericGameplayAbilities -> CoreConfig -> AttributeSetDefinition.
- Name the new attribute set asset: It is recommended to name the new attribute set definition with the prefix ASDefinition_, such as ASDefinition_Health|Combat|Stamina.
- Configure code generation: Specify which project module and path the code will be generated in, the code file name, the attributes it must have, etc. You can also select a threshold template from the template drop-down list to quickly fill in the configuration.
- Click the Build/Rebuild button. After the code is generated, you need to recompile the project.
note
You can add other allowed code subpaths in Project Settings -> GGA Attribute Set Generator settings, such as "MyFolder/Attributes". By default, only the two folders, module name/Attributes|AttributeSets, are allowed.
Generated Code
Here is an example of generating gameplay attribute code from json.
Above AttributeSetDefinition generates the following code:
As you can see, just a simple set of attributes requires so much code. So code generation is given!
Blueprint Accessor Examples
Some thoughts
Since the attribute system of GAS has to be done in C++, this has hindered a large portion of blueprint users, while various solutions for blueprint users have appeared in Unreal Marketplace. Even a pure blueprint GameplayAttribute solution appeared.
However, I think that if you take a big detour to use GameplayAttribute with all kinds of hacks just because you have a fear of code projects, I think you are putting the cart before the horse.
What if in the future Unreal comes with blueprint support for GameplayAttribute?
What if in the future the Unreal team makes it so that GAS no longer requires C++?
Of course, this is just my own personal opinion. If you're going to develop serious games, you're always going to be faced with C++.