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"

Getting an array of all components of a certain type in blueprint

I have a blueprint that has a number of components of the same type attached to it. I would like to be able to iterate through them, is this possible? At the moment, I am manually dragging a node on for each one and combining into an array. Is there a more robust way to do this?


Product Version: Not Selected
more ▼

asked Jun 12 '14 at 08:15 AM in Blueprint Scripting

avatar image

641 44 57 89

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

As discussed in the comments, there is no function which achieves this for blueprint but it can be easily added to code. I wrote the following method to extend the Actor class to allow for this functionality. When I get a minute to tidy it up, I will make a pull request on Github, until such a time here is the function I am using:

 TArray<UActorComponent*> AActor::GetComponentsOfType(UClass* ClassFilter) const
     TArray<UActorComponent*> ValidComponents;
     for (UActorComponent* Component : OwnedComponents)
         if (Component && Component->IsA(ClassFilter))
     return ValidComponents;

The main limitation this has is, in bluprint, you must loop through the returned array and cast it to the actual component type you need.

Like I said, when I get some time, I'll investigate into whether it is possible to have generic blueprint functions so the function could actually return the correct type.


I have created a pull request, you can see it here:

more ▼

answered Jun 12 '14 at 11:45 AM

avatar image

641 44 57 89

(comments are locked)
10|2000 characters needed characters left

there's definitely a way to do that in C++, probably with the degree of control that you're after. I've never used it, but have you looked at GetActorListFromComponentList node? It takes an array of components and outputs an array of actors, and it has a class filter. You could maybe filter for static mesh or whatever it is that you want to isolate and then cast from actor class on the other side of the array that it makes?

more ▼

answered Jun 12 '14 at 09:11 AM

avatar image

756 79 60 233

avatar image thk123 Jun 12 '14 at 09:28 AM

Yeah I saw that node, seems to do literally the inverse of what I need! Or have I misunderstood? If I need an array of components, surely no way of casting from an array of actors since components don't inherit from actors?

Unless there is a way to do that, I shall write a C++ function to provide the node, thanks :)

avatar image robbiecooper Jun 12 '14 at 09:38 AM

Urr, yeah, that is correct. Sorry hadnt really thought it through. In C++ its pretty straightforwards.

TArray Components;


Then just check what component is what with IsA;

if (PrimComp->IsA(UStaticMeshComponent::StaticClass())) { blar blar}

avatar image thk123 Jun 12 '14 at 10:22 AM

Yup, just written a method in AActor to expose it to blueprint, so hopefully that's all sorted... I'll post it once I've checked it works, thank you :)

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