ue4 c++ add tag
To add a tag in Unreal Engine 4 (UE4) using C++, follow these steps:
Step 1: Open your project in the Unreal Editor. Step 2: Create a new C++ class or open an existing one that you want to add the tag to. Step 3: In the header file (.h) of the class, include the "Engine/EngineTypes.h" header. Step 4: Declare a variable of type "FGameplayTag" in the class. This will be used to store the tag. Step 5: In the source file (.cpp) of the class, define the variable using the "DECLARE_GAMEPLAY_TAG" macro. For example:
DECLARE_GAMEPLAY_TAG(MyTag, MyTagName);
Here, "MyTag" is the name of the variable, and "MyTagName" is the name of the tag you want to add.
Step 6: In the constructor or any other appropriate function, assign a value to the tag variable using the "FGameplayTag::RequestGameplayTag" function. For example:
MyTag = FGameplayTag::RequestGameplayTag(TEXT("MyTag.MyTagName"));
Here, "MyTag" is the variable declared earlier, and "MyTagName" is the name of the tag you want to add.
Step 7: You can now use the tag variable in your code to check for or apply the tag as needed. For example:
if (MyTag.MatchesTag(FGameplayTag::RequestGameplayTag(TEXT("MyTag.MyTagName"))))
{
// The tag matches, do something.
}
In this example, we check if the tag stored in "MyTag" matches the tag with the name "MyTag.MyTagName".
That's it! You have successfully added a tag in UE4 using C++. Remember to save your files and rebuild your project for the changes to take effect.