x

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.

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

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
Tags:
more ▼

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

avatar image

Frisco
48 8 14 17

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

0 answers: sort voted first
Be the first one to answer this question
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