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"

Loading Blueprints with ObjectLibrary

I am trying to load a set of Blueprints from a path with the object library. These Blueprints are the lowest part in the following inheritance tree:

AFurniture (C++) -> FurnitureBP (Blueprint) -> Chair, Table, Carpet (Blueprints)

All these Blueprints (Chair, Table, etc) are in the same path and I am trying to load them with the following code:

 ULibrary* ULibrary::LoadLibrary(const FString & LibraryPath, UClass * InBaseClass)
 {
     UObjectLibrary* uol;
 
     uol = UObjectLibrary::CreateLibrary(InBaseClass, true, GIsEditor);
     uol->AddToRoot();
 
     int32 BlueprintsNumber = uol->LoadBlueprintAssetDataFromPath(LibraryPath);
 
     TArray<FAssetData> FurnitureAssets;
     uol->GetAssetDataList(FurnitureAssets);
 
     ULibrary* NewLibrary = NewObject<ULibrary>();
 
     for (int32 b = 0; b < FurnitureAssets.Num(); b++) {
         UBlueprint* BluePrint = Cast<UBlueprint>(FurnitureAssets[b].GetAsset());
         
         UClass* FurnitureClass = BluePrint->GetClass();
 
         if (FurnitureClass) {
             NewLibrary->Add(FurnitureClass);
         }
     }
 
     return NewLibrary;
 }

The problem is that I do not know how to get the proper UClass from each element. I think they are detected ok as I can call BluePrint->GetName() and get the proper names (Chair, Table, etc), but I need the UClass to be able to spawn them in game.

Is this the right way to do it?

Product Version: UE 4.10
Tags:
more ▼

asked Mar 09 '16 at 10:44 AM in C++ Programming

avatar image

SuperRey
32 6 9 11

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Hey, I just had a very similar problem and found the solution! If you want to load Blueprint classes you should use ObjectLibrary->GetBlueprintsFromPath like this:

 ItemLibrary = UObjectLibrary::CreateLibrary(AItem::StaticClass(), true, GIsEditor);
 ItemLibrary->AddToRoot();
 ItemLibrary->LoadBlueprintsFromPath(TEXT("/Game/FPSTemplate/Items"));

And then you need to use GetObjects instead of GetAssetDataList like so:

 TArray<UBlueprintGeneratedClass *> ClassesArray;
 Library->GetObjects<UBlueprintGeneratedClass>(ClassesArray);
 
 for (int32 i = 0; i < ClassesArray.Num(); ++i)
 {
     UBlueprintGeneratedClass * BlueprintClass = ClassesArray[i];
     OutClasses.Add(BlueprintClass);
 }

Also UBlueprint's do not exist in a packaged game, this would cause a crash. Hope that helps!

more ▼

answered Mar 09 '16 at 04:03 PM

avatar image

Fluppi393
457 35 33 54

avatar image SuperRey Mar 09 '16 at 04:47 PM

Wow! Exactly what I wanted! It was in front of me all the time, hahaha.

Thank you!

avatar image wangsj Nov 21 '16 at 05:05 AM

"UBlueprint's do not exist in a packaged game" So how to deal with it? if I want to run in package game

avatar image SuperRey Nov 21 '16 at 11:26 AM

I have been using the code as proposed by Fluppi393 with Shipping configurations with no issues at all. Just make sure the folder where you have your Blueprints is added to the cooking process. You can force folders to be added to the cook in the Project Settings.

(comments are locked)
10|2000 characters needed characters left
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