I’m just now learning how to use Gameplay Tags due to a blog I found explaining what they were. I’ve started setting the system up for my game but I came across an issue with the Get All Actors Of Class Matching Tag Query node.
I want to use this node dynamically and create the query input it requires from a tag container variable. Does anyone know how to properly use this node and is there a reason it can’t be dynamic or am I just not seeing something?
Edit: Here is a better representation of what I was looking for.
Edit 2: Apparently this is an issue with the node itself since it requires an interface that doesn’t look like its exposed to blueprint. According to this video the node has issues with blueprint so does anyone know when this will be resolved?
This approach should work.
Add a variable called tag of type integer to your blueprint.
Initialise this with a unique value say 0.
Then use the get all actor by class node
Loop over each item with a foreachloop
Take the element pin an connect it to a get tag node. Make sure context sensitive is unchecked
Then use a conditional statement to compare your tag value to 0.
If it matches then you have the reference to the instance of this class.
A peep in the source code of UBlueprintGameplayTagLibrary make it clear how the GetAllActorsOfClassMatchingTagQuery is working.
in Unreal 5.4.4, BlueprintGameplayTagLibrary.cpp line 120, after getting all the actors of the specified class, the code validate the presence of the inteface.
IGameplayTagAssetInterface* GameplayTagAssetInterface = Cast<IGameplayTagAssetInterface>(Actor);
if (GameplayTagAssetInterface != nullptr)
{
I created a version that does not need the IGameplayTagAssetInterface.
It just checks if the UAbilitySystemComponent is in the actor and uses it.
/**
* Gets all actors of a specific class that have an AbilitySystemComponent with tags matching the given query.
* The OutActors array will be of the same type as the ActorClass input.
* @param WorldContextObject The world context.
* @param ActorClass The class of actors to search for.
* @param GameplayTagQuery The gameplay tag query to match against.
* @param OutActors The array of actors that match the query.
*/
UFUNCTION(BlueprintCallable, Category = "GameplayTags",
meta = (WorldContext = "WorldContextObject", DeterminesOutputType = "ActorClass", DynamicOutputParam = "OutActors"))
static void GetAllActorsOfClassMatchingTagQueryInComponent(UObject* WorldContextObject, TSubclassOf<AActor> ActorClass,
const FGameplayTagQuery& GameplayTagQuery, TArray<AActor*>& OutActors);
#include "GameFramework/Actor.h"
#include "EngineUtils.h"
void UMyAbilitySystemLibrary::GetAllActorsOfClassMatchingTagQueryInComponent(UObject* WorldContextObject, TSubclassOf<AActor> ActorClass,
const FGameplayTagQuery& GameplayTagQuery, TArray<AActor*>& OutActors)
{
OutActors.Empty();
UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
// We do nothing if no class is provided, rather than giving ALL actors!
if (ActorClass && World)
{
for (TActorIterator<AActor> It(World, ActorClass); It; ++It)
{
AActor* Actor = *It;
if (IsValid(Actor))
{
// Find the AbilitySystemComponent on the actor
UAbilitySystemComponent* ASC = Actor->FindComponentByClass<UAbilitySystemComponent>();
if (ASC)
{
FGameplayTagContainer OwnedTags;
ASC->GetOwnedGameplayTags(OwnedTags);
if (OwnedTags.MatchesQuery(GameplayTagQuery))
{
OutActors.Add(Actor);
}
}
}
}
}
}