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:
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?