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"

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:

alt text

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?

Product Version: UE 4.18
Tags:
more ▼

asked Feb 28 '18 at 10:21 PM in C++ Programming

avatar image

Nialna
26 2 6 9

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

1 answer: sort voted first

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

more ▼

answered Mar 01 '18 at 05:44 AM

avatar image

HollingsworthDan
136 2 4 7

avatar image Nialna Mar 01 '18 at 10:36 AM

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.

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