Store blueprint component in an array

I have a blueprint (based on a cpp class) which contains another blueprint as its component:

How can I store it in the editor into an array (so that I’m able to access it via cpp)? I thought of something like

UPROPERTY(EditDefaultsOnly, Category = "Room settings")
TArray<TSubclassOf<ADoor*>> Doors;

but this gives me a “OtherCompilationError (5)”…

TSubclassOf is templated with the actual class, not with a pointer.

TArray<TSubclassOf<ADoor>> DoorBlueprints;

Are you trying to access the component itself or are you trying to access the blueprint to spawn more instances of the component?

If you want to collect multiple instances of your door actor, you just want to store the pointers in the array:

TArray<ADoor*> Doors;

I would like to be able to do something like this:

room->Doors[0].Open();

I already tried the Tarray pointer but i can’t add the door to the array.

Do I have to do it at runtime via cpp?

Try including “BlueprintReadWrite” in your UPROPERTY macro and change “EditDefaultsOnly” to “EditAnywhere” (at least for now):

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Room settings")
 TArray<ADoor*> Doors;

You should be able to add the pointer to your array within the Blueprint editor. Do you see the array property in the blueprint? Is it editable but not accepting your component, or is it greyed out?

As you can see in the screenshot (in my last comment on your prev answer), the property appears in the editor, but I can’t add the door to the array.

You’re not going to be able to reference the ADoor actor directly in the Blueprint viewport. In your hierarchy you’re adding a UChildActorComponent, which is not an ADoor actor but rather holds your ADoor actor; so it’s not valid for the array of ADoor pointers.

You’ll need to get a reference to your child actor and call GetChildActor from it, then add the returned pointer to your array. You can do that in the Blueprint construction script, or in the event graph of your blueprint; or you can spawn your UChildActorComponents in your cpp constructor, or do them dynamically during runtime in another method.

OR, you can make your array an array of child actor components:

  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Room settings")
  TArray<UChildActorComponent*> Doors;

Then you can do this where you want to use the doors:

UChildActorComponent* ChildDoor = Room->Doors[0]->GetChildActor();

if (ChildDoor) {
    ChildDoor->Open();

}

You can see more about how to work with UChildActorComponents here:

That’s exactly what I needed, thx.