Elegant management of GameplayTag in the Unreal Engine

中文点这里


introduce

GameplayTag is heavily used in the project through Blueprints and C++. The following are the ways that everyone adds GameplayTags:

Add a DataTable with TableRow set to FGameplayTagTableRow in the settings.

Add it in the GameplayTag editor.

Write it directly in .ini files (yes, I do this -.-).

Clearly, we need order and rules!

  1. I have decided to manage GameplayTags using DataTable in the following way:

  2. Use a CompositeDataTable as a container and add multiple child GameplayTagDataTables.

  3. Each child GameplayTagDataTable only contains one type of GameplayTag, for example, the UI DataTable is named DT_UIGameplayTags.

  4. Each child GameplayTagDataTable has a fixed prefix. For example, the UI-related GameplayTags are named http://UI.XXX.XXX.

  5. I created an EditorBlueprintUtility in Blueprint to check for duplicate GameplayTags in the DataTables and generate code like this:

#ifndef UI_XXX_XXX
/**
 *	GameplayTagTableRow DevComment
 */
#define UI_XXX_XXX FGameplayTag::RequestGameplayTag(FName("UI.XXX.XXX"))
#endif

This saves me from the tedious work of copying, pasting, and checking for duplicates.

It’s very smooth and elegant. I’m truly amazed by it.

GameplayTagMacroGenerator plugin

Later, I rewrote the EditorBlueprintUtility in C++ at home and added editor support to improve the user experience.

I named it GameplayTagMacroGenerator (GTMG for short).

Marketplace link

Features

  1. One-click generation of GameplayTag macro code. The generated code includes macros, macro checks, and comments.
#ifndef UI_XXX_XXX
/**
 *	GameplayTagTableRow DevComment
 */
#define UI_XXX_XXX FGameplayTag::RequestGameplayTag(FName("UI.XXX.XXX"))
#endif

The GameplayTag collection source includes the GameplayTagTableList in settings and the DefaultGameplayTags.ini configuration file.
2. Check if the GameplayTag is duplicated. Duplicated GameplayTags will be printed as warnings in the console.
3. In addition to support for C++ macros, it also supports popular script language frameworks such as Unlua and Puerts.
4. Full code comments are provided for easy secondary development and learning.
5. Sure, here is the translation of my previous response:

// Line comments

AND

/**
 *	Documention comments
 */
  1. Aligning C++ code makes compulsive disorders feel comfortable.

Usage

  1. In the Unreal Engine Marketplace search GameplayTagMacroGenerator code plugin, download and install.

  2. Open the project, there is an additional button Icon20 on the Main Toolbar, which can also be found in the Main Menu - Window.

  3. Create a new CompositeDataTable named CDT_GameplayTags, select GameplayTagTableRow for the row structure.

    Screenshot2

  4. Create a new DataTable named DT_CharacterGameplayTag, select GameplayTagTableRow for the row structure.

    Screenshot3

  5. Add several pieces of data to the DT_CharacterGameplayTag, such as:

    Row Name will be used as the macro name.

    Tag will be the target GameplayTag.

    Dev Comment will be annotated above the macro.

  6. Open CDT_GameplayTags, add DT_CharacterGameplayTag to Parent Tables. here can add many GameplayTagDataTable.

    After, add CDT_GameplayTags to Project Settings - Project - GameplayTags - GameplayTagTableList

  7. After saved, open Main Menu - Project Settings - Project - GameplayTag Macro Generator, fill in settings.

    There are three settings here:

    CppMacroFileOutputPath: file output path, select the path for the header file in a project

    CppMacroFileOutputName: file name, default to MyGameplayTags, can be modified at will

    CommentStyle: Comment style, default to document comment, with two options: document comment and line comment

  8. Click LOGO generate macro file, then you can obtain the target GameplayTag through a macro in code.

1 Like