How to add child actor from array in construction script?

The array has to be “Exposed on spawn” and then you can asign the blueprint in the array slot from the editor in the details panel. note: The array has to be public( checkbox “editable”).

Your array should be of type “class” and when chosing the random element select the class from the array and feed it into the spawn actor node.

Kind regards,

Eric

HyperReuts

Hi,
I was wondering how I could get different bp actors (lets say some differen types of door Blueprints and different types of Pickup bp’s) inside my construction script. The only way I got it to work so far is via drag and drop from the asset library in my construction script, I wonder how I would get them in via the actions menu in blueprint, also I would like to have them put in an array to choose them randomly afterwards, like I do it with “add static mesh” too.
At the moment I am randomizing what child actor to choose with lots of branches and random bools in it, and via drag and drop catched child actors… that feels uber wrong! :stuck_out_tongue:

Any hints or links would be very appreciated!

Thanks

Hi Eric,
Thanks for your fast reply! You mean like this? Cause this also does not work… i think my Problem is even earlier in the process, I dont get the child actors inside my construction script, only via drag and drop. I tried object reference variable etc. But when i try to use the node “add child actor” it does not work, only the on drag and drop generated “add child actor” nodes work

If you add a breakpoint at the branch, does it activates?

I see you call “Get all Actors from Class”; but the actors don’t exists yet, right? So wouldn’t it make more sense to spawn the actors first?

Eric: I just noticed it works when I choose the actor in the drop down in the details panel. Thats awesome! I am one step closer :slight_smile:

BUT I would like to set it up from an array. when I Plug the exact same actor in the target slot of the add child actor node it does not work anymore. My Goal would be like described above choose some actors and make an array from them ( that allready works) and plug them into the add child actor node, but for some reason this does not work.

HAH: yes Problem is I dont know how to add random child actors from array.

1 Like

yes, Building the array works, the add child component node does not work anymore when i plug it in, evenwhen i plug in the same actor reference what i had choosen in the details drop down it stops working… nor as single object reference nor from array.

Like i said, when i choose the actor in the drop down in the details panel (you can see it on the right in the attachment) it works as expected. So I thought in construction script this is the way to add my actors instead of “spawn actor from actor from class” I use spawn actor in event graph, but here in construction script there is no option for that. I need to find a way to change the class of the add child actor component node.

I think there is some terminology confusion here, like you can see in the last attachment, there is no “spawn actor” in construction script. And “add child actor component” works when the actor is selected in the “child actor class” drop down, the problem was that i cannot acces this in the graph… But I found a workaround, instead of putting references of actors in an array to put them randomly in the child actor class slot of the add child actor component node. I now just added a add child actor component node per object i want to add (or spawn ;)) and use a switch on int node to randomize it.

Generate random numer from lengt of array, from zero till the length of the array. Then use the array get node using the randomly generated index to select random child actor.

I do not see “Spawn” actor of class? What do you mean by not working anymore, it is not constructed to do something? The actor cannot have two parrent btw!

I see that there is no return value! The variables door and obstacle probably do not have an input. You should reference these or spawn and put them in these references.

You can only spawn actors in constructionscript, not child actors.

Workarround: You can spawn a actor and attatch it to a child actor component

Happy that it works:)

There is way to set class name from blueprint graph. Checkout this, it works for me

In case anyone is still checking this thread, it definitely CAN be done. In my construction script I have an array of classes (Main Equipment C) which I want to become child actors. I add them using the a “ForLoop” and “Add Child Actor Component” node and then add the output of that node to an array of child actors (Main Equipment A), and immediately after “Set Child Actor Class” from my Array of classes.

Then in my event graph, when I need to trigger something on one of my child actors, I get it from my Main Equipment A array of child actors, and then “Get Child Actor” in order to get the reference I need to do it.

Hopefully this helps someone.

2 Likes