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"

Store blueprint component in an array

I have a blueprint (based on a cpp class) which contains another blueprint as its component: 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)"...

Product Version: UE 4.13
Tags:
component.png (519.4 kB)
more ▼

asked Sep 23 '16 at 03:18 PM in C++ Programming

avatar image

91378246
12 3 5 5

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

2 answers: sort voted first

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?

more ▼

answered Sep 23 '16 at 07:43 PM

avatar image

GigasightMedia
1.7k 43 13 61

avatar image 91378246 Sep 23 '16 at 08:04 PM

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.

avatar image GigasightMedia Sep 23 '16 at 10:32 PM

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:

https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/UChildActorComponent/index.html

avatar image 91378246 Sep 24 '16 at 08:10 AM

That's exactly what I needed, thx.

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

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;
more ▼

answered Sep 23 '16 at 06:10 PM

avatar image

GigasightMedia
1.7k 43 13 61

avatar image 91378246 Sep 23 '16 at 07:10 PM

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. room Do I have to do it at runtime via cpp?

room.png (570.4 kB)
(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