How can my C++ Actor Component contain a list of blueprint classes that can be modified in the editor?

I have a C++ component that generates a map. I want this component to be able to place random vegetation.

Each possible type of vegetation is a blueprint actor, and I want my component to be able to spawn any of them.

For that, I want to have an array in the C++ component that contains reference to the blueprint classes, so they can later be spawned. This array should be editable in the editor.

I found this thread which asks a similar question, and one response gives the following solution:

 static ConstructorHelpers::FObjectFinder<UClass> FloorCellClassFinder( TEXT( "Blueprint'/Game/YourProject/SomeFolder/YourBP.YourBP_C'" ) );
 FloorCellClass = FloorCellClassFinder.Object;

The problem with this solution is that you still need the path to the blueprint hardcoded in your code. What I want is something that can be modified in the editor, without having to edit the code.

I have found another answer in this question with the following solution:

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Guns, meta=(AllowPrivateAccess = "true"))
 class UClass* Weapon;

This looks like what I would be looking for, except it doesn’t work. I tried adding a UClass* field this way to my component, and it doesn’t appear in the editor at all.

Here is my code:

USTRUCT(BlueprintType)
struct FVegetation {
	GENERATED_USTRUCT_BODY()
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Vegetation")
	int Density = 100;
	UPROPERTY(EditAnywhere, BlueprintReadWRite, Category = "Vegetation", meta = (AllowPrivateAccess = "true"))
	class UClass* VegetationActor;
};

And here is the result in the editor:

232354-ue4-vegetation.png

As you can see, the “VegetationActor” property doesn’t appear at all.

Is there any way I can have an editable list of blueprints to spawn like that, or is the only option to hardcode all of them?

ok 1. Blueprints take too much CPU for you to run around sprinkling them down like grass seeds.

  1. Use the asset registry, which has a complete list of all of your assets under content. Including the BP’s you want to sprinkle around like grass seeds.

Should look something like this:

	IAssetRegistry* AssetRegistry;
    AssetRegistry = &FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry")).Get();
	
	TArray<FAssetData> AssetDatas;
	AssetRegistry->GetAssetsByClass(UBlueprint::StaticClass()->GetFName(), AssetDatas);

But you can make it easy for yourself if you create an empty class that you derive your BP’s you want to find. Then you can change the

UBlueprint::StaticClass()->GetFName()

to

<MyGrassSeeds>::StaticClass()->GetFName();

Thanks for your answer, this seems like it could work for me.

For precision, the reason I want to spawn blueprint actors is that they will run special code because they are not fully passive. For the ones that don’t need to run code, I can probably just spawn static meshes to avoid wasting performance I suppose.