Tutorial: Enhanced Input Binding with Gameplay Tags C++

This tutorial covers setting up a foundational Enhanced Input system in the First Person Template. This a minimalized version of the system implemented in the Lyra sample. We will cover setting up a simple Asset Manager, using native Gameplay Tags, input config assets, and binding inputs to character functions via gameplay tags.

https://dev.epicgames.com/community/learning/tutorials/aqrD/unreal-engine-enhanced-input-binding-with-gameplay-tags-c

3 Likes

Hi,
I did understand everything and did follow through everything but, i did stuck at a problem at the
DemoEnhancedInputComponent->BindActionByTag(InputConfig, DemoGameplayTags.InputTag_Move, ETriggerEvent::Triggered, this, &ADemoPlayerCharacter::InputMove);
the tags are passing as none but if i restart the engine it works fine for the first time but if change some code(such as changing a bool value) it doesn’t work and i ineed to restart the engine. Could you help me with this.

1 Like

“EnhancedInput” needs to be added to the build.cs as well - should be mentioned in the tutorial

2 Likes

This is all great, of course, but why do you need to operate with tags at all? It would be great if you described the problem that this approach solves.

1 Like

Hi Chumble,
Thanks for the reply but, i had already added it but it didn’t solve it.
But, i think it was related to “Hot Reload” and switched to use “Live Coding” and now it works perfectly fine.

Hi Acterix,
I think it makes it easier to work with tags in C++, as i was using them for my project which has many player states and abilities that needs to be switched so, using gameplay tags helps a lot to keep track of all those and helps to keep the code clean as we continue to work on the project.
so, as i was thinking of modifying the project to use the “Enhanced Input System” and came across this tutorial i thought it will be good if i use this in my project as i was already using the gameplay tags and since i was also thinking of changing the input mappings on the runtime or giving the player the ability to map their own controls, using this helps me to keep a better track of something and also helps to adjust or modify the code base easily.

I hope this answers your question. If it doesn’t or if you need any information related to this you can reply to this post, I will try to help you.

I love the tutorial and had some problems, but I figure them out. I would recommend changing the default Asset Manager class portion, it took me a bit too long to find it. If you are finding that there are no InputTags in your InputConfig data asset, the text tells you to change the Default Asset Manager to your Asset Manager that you have created in the Engine settings. This is located in Project Settings under the heading Engine in General Settings. Located 'Defaults Classes", you might have to expand “Advanced” to local the Asset Manager Class.

3 Likes

This is immensely helpful.

I cannot help to notice that access to the Input Action Assets in C++ (via the gameplay tags) implies a considerable overhead. Something like BindWidget for UMG/C++ would be nice. Well, or defining the Input Action assets from C++ (and then exposing them, if necessary, to the editor/blueprint world) … don’t know if that’s possible.

Great tutorial to learn EnhancedInput. I understood every step of the tutorial and implemented it myself, but I don’t think I need GameplayTag for mapping, I still haven’t found an application scenario that needs GameplayTag for influence.

1 Like

Hi,

I can’t seem to get this project to build. I’m pretty new so maybe I’m doing something wrong:

  • I dowloaded UE 5.2 via Epic Games Launcher
  • I created a C++ FirstPerson Sample Instance
    -The editor started, I can play the map in the editor
  • I start Visual Studio 2022, load the project and do Start Debugging, everything is fine, the Editor starts, I can play the map like before
  • I add a new class using the New C++ class, I named it MyGameplayTags, did not derive it from anything.
  • VS2022 opens
  • to be sure I exit the editor, exit VS 2022 and restart it
  • I paste the content from the tutorial into the files created
  • I do Start Debugging in Visual Studio 2022 like before, but now I get linker errors:
    1>MyGameplayTags.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: struct FGameplayTag __cdecl UGameplayTagsManager::AddNativeGameplayTag(class FName,class FString const &)" (__imp_?AddNativeGameplayTag@UGameplayTagsManager@@QEAA?AUFGameplayTag@@VFName@@AEBVFString@@@Z) referenced in function "protected: void __cdecl FMyGameplayTags::AddTag(struct FGameplayTag &,char const *,char const *)" (?AddTag@FMyGameplayTags@@IEAAXAEAUFGameplayTag@@PEBD1@Z) 1>MyGameplayTags.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl UGameplayTagsManager::DoneAddingNativeTags(void)" (__imp_?DoneAddingNativeTags@UGameplayTagsManager@@QEAAXXZ) referenced in function "public: static void __cdecl FMyGameplayTags::InitializeNativeTags(void)" (?InitializeNativeTags@FMyGameplayTags@@SAXXZ) 1>MyGameplayTags.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) private: static void __cdecl UGameplayTagsManager::InitializeManager(void)" (__imp_?InitializeManager@UGameplayTagsManager@@CAXXZ) referenced in function "protected: void __cdecl FMyGameplayTags::AddTag(struct FGameplayTag &,char const *,char const *)" (?AddTag@FMyGameplayTags@@IEAAXAEAUFGameplayTag@@PEBD1@Z) 1>MyGameplayTags.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) private: static class UGameplayTagsManager * UGameplayTagsManager::SingletonManager" (__imp_?SingletonManager@UGameplayTagsManager@@0PEAV1@EA) referenced in function "protected: void __cdecl FMyGameplayTags::AddTag(struct FGameplayTag &,char const *,char const *)" (?AddTag@FMyGameplayTags@@IEAAXAEAUFGameplayTag@@PEBD1@Z)

Can you help me solve this issue? I Don’t know what I’m doing wrong. I searched for linker errors like this, and solutions tell me I need to modify some build.cs file, which I don’t have.

Cheers

Ulf

It looks like you’re missing the GameplayTags module. Check that you added the “GameplayTags” entry to your PublicDependencyModuleNames in your Build.cs file.
Unreal Engine Modules | Unreal Engine 5.0 Documentation

#pragma once

#include "CoreMinimal.h"
#include "Engine/DataAsset.h"
#include "GameplayTags/Classes/GameplayTagContainer.h"
#include "InputConfig.generated.h"

class UInputAction;
struct FGameplayTag;


/**
 * FTaggedInputAction
 *
 *	Struct used to map an input action to a gameplay input tag.
 */
USTRUCT(BlueprintType)
struct FTaggedInputAction
{
	GENERATED_BODY()

public:

	UPROPERTY(EditDefaultsOnly)
	const UInputAction* InputAction = nullptr;

	UPROPERTY(EditDefaultsOnly, Meta = (Categories = "InputTag"))
	FGameplayTag InputTag;
};

/**
 *
 */
UCLASS()
class MYPROJECT_API UInputConfig : public UDataAsset
{
	GENERATED_BODY()

public:
	// Returns the first Input Action associated with a given tag.
	const UInputAction* FindInputActionForTag(const FGameplayTag& InputTag) const;

public:
	// List of input actions used by the owner. These input actions are mapped to a gameplay tag and must be manually bound.
	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Meta = (TitleProperty = "InputAction"))
	TArray<FTaggedInputAction> TaggedInputActions;
};

You definitely want to replace the TArray<FTaggedInputAction> TaggedInputAction by TMap<FGameplayTag, UInputAction*> TagMap and scrap the struct FTaggedInputAction as well as FindInputActionForTag. It just becomes TagMap[SomeTag].