Introduction
Inspired by Lyra's GameplayTagStack, this mechanism tracks and manages dynamic attribute through a GameplayTag-to-Integer mapping. In GIS, this concept has been further expanded and is referred to as the Tag Attribute Container.
For C++ User only
This article is intended only for C++ users who wish to develop other game systems using this system; Blueprint users need not read this article.
Tag Attribute Container
GIS encapsulates 2 approaches to implement a dynamic attribute system, which are as follows:
- GameplayTagIntegerContainer: Contains a list of GameplayTagInteger entries, each representing a Tag-to-Int32 key-value pair.
- GameplayTagFloatContainer: Contains a list of GameplayTagFloat entries, each representing a Tag-to-float key-value pair.
These containers are implemented using FastArraySerializer, ensuring efficient network replication and simplified callbacks for data change notifications. Each entry in the container is also marked with SaveGame, facilitating data serialization for single-player games or server-side operations.
Steps to Use Attribute Containers
Taking ItemInstance as an example:
Add a Container to your class.
In the constructor, set the current object as the ContainerOwner of the container. (Do it inside initialize component if you are using actor component as owner.)
Ensure that the field is properly replicated over the network, with replication conditions customized based on your project requirements.
Ensure that your class implements the IGIS_GameplayTagIntegerContainerOwner and IGIS_GameplayTagFloatContainerOwnerinterface.
Implement the OnTagFloatUpdate and OnTagIntegerUpdatemethod from the interface, which allows you to respond to attribute changes.
OnTagFloatUpdate and OnTagIntegerUpdateis called whenever an attribute is changed, on both the server and client sides.
Application Cases
This feature is designed to simplify the implementation of dynamic attributes, with reusable code.
Item instance utilize this dynamic attributes feature. Naturally, you may also apply this to other systems beyond just inventory management.
Attributes and fragment state
Tag attributes suit integer or float values keyed by Gameplay Tag. Structured state can use a fragment's compatible state type and Mixin container. For custom data that must persist or replicate, check SaveGame fields, target objects, and replication setup; see Data Mixin System and Save and Load.