How to iterate over actor static mesh components in a blueprint?

Hi there!

I recently stumbled over the following problem. Imagine you have a blueprint actor “wall” that is build of N bricks = simple static mesh components.
Now you are in the wall’s class blueprint and would like to change a property (for example “simulate physics”) of all the bricks in one go. One of the way might be to get children of the root wall component (which is an arrow in this case) in an array, iterate over them using a for loop and change the particular property of each brick in there…

The problem is I don’t know how to get the array of components the actor (wall) is built of!? Note the bricks are not attached to the wall actor via “Add Child component” or similar. They are just static mesh components added via blueprint Components editor and made children of the root Arrow component of the wall actor.

None of the “Get Child Components” set of the blueprint functions seems to work. I always get an empty array…
I’m using UE4.3. Didn’t try it in different versions.

Could you, please, suggest me a way to get the bricks of a particular wall in this setup? Note there might be more walls in the scene and each of them needs to be controlled separately.

P.S.: The “wall” example here is just to illustrate the problem, so please don’t comment the usefullness of such a setup.:wink:

Thank you in advance!

Bump – I’m running into the same problem. I’m in a base BP class and trying to write functionality that will apply to 30 or so child BP classes and the various static mesh components inside those. Right now, though, I’m not seeing a way to iterate over the static mesh components in a generic way.

“For the second case, you’ll once again have to create an array but you need to add your components to it manually, which can take some time.”

That doesn’t really answer the question, though. The question is how to access them WITHOUT having to reference them directly.

Like, ideally, there would be a GetNumPrimitiveComponents() function we could call to get the number of primitive components in a BP, and a GetPrimitiveAtIndex( int ) function I could use to iterate over the array. I could add that functionality pretty easily to my own classes via C++, but it seems like there should be a way to do that in the engine itself.

Hey guys, you’re on the right track with arrays, so let me push you a bit further in the right direction. There are two ways of achieving this depending on whether you’re creating something that can be constructed in a bp script (like a wall) or something you just bring together in the components screen that can’t be created based on a rule.

For the first case I would recommend using a for loop (in fact two for loops) to create rows of static mesh components and setting them to brick within the loop and storing them in an array. Event begin play or the construction script is the place to do this.

For the second case, you’ll once again have to create an array but you need to add your components to it manually, which can take some time.

After that you can access the necessary static mesh component by getting it from the array. You can also use trace line functions for this and get hit component then modify it, e.g. if you shoot a brick, only that one gets destroyed/crumbles.