# How can i made a tracking system for turrets with gameplaytags?

**URL:** <https://forums.unrealengine.com/t/how-can-i-made-a-tracking-system-for-turrets-with-gameplaytags/487317>\
**Category:** C++\
**Tags:** tags, unreal-engine, UE4, question, CPP\
**Created:** [August 11, 2021, 11:36am UTC](https://forums.unrealengine.com/t/how-can-i-made-a-tracking-system-for-turrets-with-gameplaytags/487317 "2021-08-11T11:36:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![BeerenBubbleGume](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BeerenBubbleGume](https://forums.unrealengine.com/u/BeerenBubbleGume)\
**Post date:** [August 11, 2021, 11:36am UTC](https://forums.unrealengine.com/t/how-can-i-made-a-tracking-system-for-turrets-with-gameplaytags/487317/1 "2021-08-11T11:36:18Z")

</div>

Hi, Im trying create a tracking system for my turrets in UE C++. Im made 3 functions for this, but turrets don’t see a tags by enemys and don’t tracking thems. I don’t understand what i do wrong

That function dont work, dont find the tags on the Actors, idk why

```
void ABasicTower_CPP::FindEnemy()
{
	TArray<AActor*> FindEnemyWithTags;
	UGameplayStatics::GetAllActorsWithTag(GetWorld(), TEXT("Character.Enemy"), FindEnemyWithTags);
	
	int32 EnemyArrayLength = FindEnemyWithTags.Num();
	UE_LOG(LogTemp, Warning, TEXT("Lenth of array is: %s"), FindEnemyWithTag.Num())
	if(EnemyArrayLength != 0)
	{
		
		
		int CurrentIndex = 0;
		for(int Index = 0; Index <= EnemyArrayLength; ++Index)
		{
			if(Index != 0)
			{
				AActor* CurrentEnemy = FindEnemyWithTags[Index];
				float Lenth = GetLengthToTurret(CurrentEnemy);
				float MinLength = 900.f;
				if(Lenth <= MinLength)
				{
					MinLength = Lenth;
					CurrentIndex = Index;
					RotationTowerHead(FindEnemyWithTags[CurrentIndex]);
					GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Find enemy"));
				}
			}
			else
				GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Array lenth = 0"));
		}
		
	}
	
}
```

---

<div class="post-metadata">

**Author:** ![chrudimer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chrudimer/32/918651_2.png) [@chrudimer](https://forums.unrealengine.com/u/chrudimer)\
**Post date:** [August 11, 2021, 12:04pm UTC](https://forums.unrealengine.com/t/how-can-i-made-a-tracking-system-for-turrets-with-gameplaytags/487317/2 "2021-08-11T12:04:00Z")

</div>

Hi, do you want to use tags or GameplayTags? Cause in your question header you say GameplayTags but GetAllActorsWithTag looks for tag, not GameplayTag and GameplayTags are constructed via `FGameplayTag::RequestGameplayTag("something")`, AFAIK `TEXT("something")` will not work.

---

<div class="post-metadata">

**Author:** ![BeerenBubbleGume](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BeerenBubbleGume](https://forums.unrealengine.com/u/BeerenBubbleGume)\
**Post date:** [August 11, 2021, 1:15pm UTC](https://forums.unrealengine.com/t/how-can-i-made-a-tracking-system-for-turrets-with-gameplaytags/487317/3 "2021-08-11T13:15:01Z")

</div>

I want to use GameplayTags, but dont see the difference. How can I work with GamplayTags in this case?

---

<div class="post-metadata">

**Author:** ![BeerenBubbleGume](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BeerenBubbleGume](https://forums.unrealengine.com/u/BeerenBubbleGume)\
**Post date:** [August 11, 2021, 1:22pm UTC](https://forums.unrealengine.com/t/how-can-i-made-a-tracking-system-for-turrets-with-gameplaytags/487317/4 "2021-08-11T13:22:40Z")

</div>

I used `FGameplayTag::RequestGameplayTag("something")` in the other class from the start. Idk what function can seach this tag and put it in array

---

<div class="post-metadata">

**Author:** ![chrudimer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chrudimer/32/918651_2.png) [@chrudimer](https://forums.unrealengine.com/u/chrudimer)\
**Post date:** [August 11, 2021, 5:14pm UTC](https://forums.unrealengine.com/t/how-can-i-made-a-tracking-system-for-turrets-with-gameplaytags/487317/5 "2021-08-11T17:14:30Z")

</div>

Ok then,

> I want to use GameplayTags, but dont  
> see the difference.

you could look at the answer here [GameplayTags and tags - Programming & Scripting - Epic Developer Community Forums](https://answers.unrealengine.com/questions/580424/gameplaytags-and-tags.html) although its a bit old.

If you want to use build in queries for gameplay tags the actor needs to implement the `IGameplayTagAssetInterface`. Therefore it makes sense to have the `FGameplayTagContainer` where you store the GameplayTags of that actor in your cpp class.

If you want to query for actors for specific GameplayTags you could use the `GetAllActorsOfClassMatchingTagQuery` function of the `UBlueprintGameplayTagLibrary` (will only work if your actors implement the `IGameplayTagAssetInterface`)

---

<div class="post-metadata">

**Author:** ![BeerenBubbleGume](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BeerenBubbleGume](https://forums.unrealengine.com/u/BeerenBubbleGume)\
**Post date:** [August 12, 2021, 11:13am UTC](https://forums.unrealengine.com/t/how-can-i-made-a-tracking-system-for-turrets-with-gameplaytags/487317/6 "2021-08-12T11:13:32Z")

</div>

Thank you, its working now (but i not understand how implamant `IGameplayTagAssetInterface` quite well)

---

<div class="post-metadata">

**Author:** ![chrudimer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chrudimer/32/918651_2.png) [@chrudimer](https://forums.unrealengine.com/u/chrudimer)\
**Post date:** [August 12, 2021, 3:57pm UTC](https://forums.unrealengine.com/t/how-can-i-made-a-tracking-system-for-turrets-with-gameplaytags/487317/7 "2021-08-12T15:57:07Z")

</div>

You could look at my second post here [Blueprint - EQS and Gameplay Tags - I need help! - #3 by ViridianGU](https://forums.unrealengine.com/t/blueprint-eqs-and-gameplay-tags-i-need-help/242086/3) there I have posted a minimalistic example of the .h file of a character that implements the `IGameplayTagAssetInterface` (no need to do anything in the .cpp file). If you inherit from actor, the changes would be the same (so also inherit from `IGameplayTagAssetInterface` and then copy everything following “// Need to store the GameplayTags…” to the .h file)

---

<div class="post-metadata">

**Author:** ![BeerenBubbleGume](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BeerenBubbleGume](https://forums.unrealengine.com/u/BeerenBubbleGume)\
**Post date:** [August 13, 2021, 4:40am UTC](https://forums.unrealengine.com/t/how-can-i-made-a-tracking-system-for-turrets-with-gameplaytags/487317/8 "2021-08-13T04:40:26Z")

</div>

Thank you again! I finally got it =^\_^=
