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?

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!

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

Thank you!

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

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.

Just to make a clear picture. UBlueprint are not packaged, that’s why @Fluppi393 used UBlueprintGeneratedClass instead of His/(Her?) example, so the solution by @Fluppi393 should work without a problem in packaged project