Download

Trying to get Blueprint asset using AssetRegistryModule.

Hi!

I am trying to get class reference in my code using the AssetRegistryModule.

This is what i tried:


FARFilter Filter2;
	Filter2.ClassNames.Add(UBlueprint::StaticClass()->GetFName());
	Filter2.bRecursiveClasses = true;
	Filter2.PackagePaths.Add("/Game/Blueprints");

	TArray<FAssetData> AssetList;
	AssetRegistryModule.Get().GetAssets(Filter2, AssetList);
	TArray<UObject*> Subclasses;
	// Iterate over retrieved blueprint assets
	for (FAssetData asset : AssetList)
	{
		// Get the the class this blueprint generates (this is stored as a full path)
		if (auto GeneratedClassPathPtr = asset.TagsAndValues.Find(TEXT("GeneratedClass")))
		{
			const FString ClassObjectPath = FPackageName::ExportTextPathToObjectPath(*GeneratedClassPathPtr);
			const FString ClassName = FPackageName::ObjectPathToObjectName(ClassObjectPath);

			UE_LOG(LogTemp, Warning, TEXT("%s"), *ClassObjectPath);
			
			FoundClass = FStringClassReference(ClassObjectPath).TryLoadClass<AC_EmptyActor>();
			if (FoundClass)
				UE_LOG(LogTemp, Warning, TEXT("Conversion Success!"));


			
			if (FoundClass)
			{
				UE_LOG(LogTemp, Warning, TEXT("Trying to spawn!"));
				GetWorld()->SpawnActor<AActor>(FoundClass, FVector(0, 0, 0), FRotator(0, 0, 0));
				
			}

If i try code above, the game will crash. If i try to add location manually doing little change:


FoundClass = FStringClassReference("/Game/Blueprints/BP_EmptyActor.BP_EmptyActor").TryLoadClass<AC_EmptyActor>();

Game won’t crash, but the FoundClass will be empty. I checked and the FString *ClassObjectPath * will return the full path for the class, so finding the class isn’t the problem here… I just don’t know how to get reference to the class, if i for example want to use it to spawn something. Any ideas what is wrong?

Foundclass is a TSubclassOf<AActor>

Try this:

Can you help me? can’t understand, why ‘blackLinesWidgetClass’ is always null?

FStringClassReference blackLinesWidgeClasstRef(TEXT(“WidgetBlueprint’/Game/Blueprints/UI/blackLines.blackLines’”));
UClass* blackLinesWidgetClass = blackLinesWidgeClasstRef.TryLoadClass<UUserWidget>();