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

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"));
		}
		
	}
	
}

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.

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

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

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 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)

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

You could look at my second post here Blueprint - EQS and Gameplay Tags - I need help! - #3 by ViridianGU 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)

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