@Everynone: Thank you very much for your hints!
The video you posted here shows exactly what I was missing! Now in the begin I misunderstood you, I read that this was DROPPED from 4.xx on, I did not really understand the tag component map. However to avoid having to maintain the map i finally succeeded using the tags to query directly for a actor component class name.
And you were right: Blueprints don’t - at least in UE 5.xxx - allow querying the names of the classes that are defined in a game at all. They do not expose the “reflection” system that is built in C++.
So the solution for me was to write a function in a C++ blueprint function library that takes a string (the tag) as a parameter and returns an “Actor Component Class” if a class with that name is defined in the game, otherwise null.
This then allows to add components defined by the content of the tags of actors, making it possible to dynamically add code and variables to actors at EventBeginPlay or at runtime. Of course such a string might also come from other sources, like data tables or http requests.
Below is how it looks in my Blueprint now, the C++ sources are attached also.
Thank you very much for pointing me to the right direction!
C++ HEADER
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "MyBlueprintFunctionLibrary.generated.h"
UCLASS()
class FUNCLIBTEST2_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "Components")
static TSubclassOf<UActorComponent> GetActorComponentClass(const FString& ComponentName);
};
C++ IMPLEMENTATION
#pragma optimize("", off)
#include "MyBlueprintFunctionLibrary.h"
#include "UObject/UObjectGlobals.h"
#include "UObject/Class.h"
#include "Engine/Blueprint.h"
#include "Engine/Engine.h"
#include "UObject/UObjectIterator.h"
TSubclassOf<UActorComponent> UMyBlueprintFunctionLibrary::GetActorComponentClass(const FString& ComponentName)
{
// Add "_C" suffix for Blueprint classes
FString FullComponentName = ComponentName + "_C";
// Try to find the class by name
UClass* ComponentClass = FindObject<UClass>(ANY_PACKAGE, *FullComponentName);
// Check if the class is a child of UActorComponent
if (ComponentClass && ComponentClass->IsChildOf(UActorComponent::StaticClass()))
{
return ComponentClass;
}
// Return nullptr if the class is not found or not a UActorComponent
return nullptr;
}