Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Trying to get Blueprint asset using AssetRegistryModule.


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

This is what i tried:

 FARFilter Filter2;
 Filter2.bRecursiveClasses = true;

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

Game won't crash, but the FoundClass will be empty. I checked and the FString [I]ClassObjectPath [/I] 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

Product Version: UE 4.15
more ▼

asked Apr 29 '17 at 03:36 PM in C++ Programming

avatar image

48 9 15 19

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hey sorry for the delay, I solved this today, and I will left this if someone else need it: Once you have your TArray AssetData; filled with the UBluprint found on your project you can create or do something else like this:

 UBlueprint* blueprinto = Cast<UBlueprint>(AssetData[0].GetAsset());
     if ((blueprinto) )
             for (TFieldIterator<UProperty> PropIt(blueprinto->GeneratedClass); PropIt; ++PropIt)
                 UProperty* Property = *PropIt;
                 // Do something with the property
                 UE_LOG(LogTemp, Warning, TEXT("%s"), *Property->GetName())

in this case just as demo, I hard coded this to the first element inside the array, cast to UBlueprint and you can access the generated class from there, in my case I simply iterate all UProperties, but you can spawn your stuff, you dont need to use FStringClassReference since you already have all this info anyway in the AssetData

more ▼

answered Dec 07 '17 at 08:14 PM

avatar image

352 9 11 17

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question