Knowledge Base: Loading Native Gameplay Tags

Article written by Branden T.

Loading Native Gameplay Tags
Native Gameplay tags need to be loaded very early during engine initialization for replication purposes. A common approach is to load native gameplay tags usin…

https://dev.epicgames.com/community/learning/knowledge-base/P8bV/unreal-engine-loading-native-gameplay-tags

4 Likes

Thanks for the article @RudyTriplett!
Your approach in Fortnite seems robust and well designed. However, it requires Engine modification and compiling UE from source. I’ve stumbled upon this article which suggests adding Native Gameplay Tags on module startup. I’ve modified the code a bit since our project needed Native Gameplay Tags even before OnLastChanceToAddNativeTags is broadcasted from UGameplayTagsManager:

MyGame.h

#pragma once
#include "CoreMinimal.h"
DECLARE_LOG_CATEGORY_EXTERN(LogMyGame, Log, All);

class FMyGameGameModule final : public FDefaultGameModuleImpl
{
	virtual void StartupModule() override;
};

MyGame.cpp

#include "MyGame.h"
#include "MyGameGameplayTags.h"
#include "GameplayTagsManager.h"
#include "Modules/ModuleManager.h"

DEFINE_LOG_CATEGORY(LogMyGame)
IMPLEMENT_PRIMARY_GAME_MODULE(FMyGameGameModule, MyGame, "MyGame");

void FMyGameGameModule::StartupModule()
{
	// Initialize your Native Gameplay Tags using your custom singleton Tag Manager
	// Your custom singleton Tag Manager should make use of UGameplayTagsManager::Get().AddNativeGameplayTag() in its initialization
	FMyGameGameplayTags::InitializeNativeTags();
	// Notify the global GameplayTagsManager that we are done adding native tags
	UGameplayTagsManager::Get().DoneAddingNativeTags(); 
}
5 Likes

For what it’s worth, 4.27 & 5 have added a more streamlined way to do native gameplay tags.

This is a good write up for it:

Yeah, we’ve looked at this solution as well but the one I posted seems cleaner and more robust. I am not even sure that these macros will work in all cases (read more below).
Having a custom TagManager singleton is a concept that I’ve taken from Epic’s Lyra project which is supposed to be representing good practices. The only thing that was not optimal there is that they initialized the Native Tags through a custom Asset Manager class. But that proved to be problematic in some cases (Asset Manager initialization happens way after Module Initialization)
We found out that when Native Tags are referenced in a Blueprint calling Static Functions, UE tries to load and read the Blueprint even before the Engine is started. If Native Tags are not loaded at that point, this Blueprint will become faulty.

Interesting, I’ll have to pay more attention to that. I would have expected an Epic provided solution to be slightly more robust in their own engine. Silly me :wink:

So far (I’m still using the UE5 EA build) I haven’t run into any of the issues you’ve described. I’d swear I’m referencing native tags from blueprint through static functions, but maybe not.

I made a post about these aswell

1 Like

At least in 5.0.3 the call to DoneAddingNativeTags() does not do anything because it requires the engine (i.e. the GEngine global variable) to have been initialized and that has not happened yet

Then it could probably be omitted :wink:

I think this approach is great. I want to have Gameplay Tags ready and available from within the C++ constructors of my gameplay abilities. This is the only way I managed to do this.

However, now I get a crash upon running the game in PIE. This crash comes out of the blue. At first even PIE used to work fine, but the editor crashed occasionally because of a problem with Gameplay Tags. Trying to fix that editor crash, I ended up with my PIE crashing now.

1 Like

Stupid mistake. I had actual invalid tags in my editor after having changed the strings in the C++ code. I just removed those, re-added them, and now it works.

1 Like