Automatically creating and layouting sub-Widgets


In my scene the players spaceship can be attacked by enemy ships.
For each enemy attacking i would like to have a little UI-element right hand side which displays some information about the enemy and add some buttons where the player can select a certain enemy actor, attack it and more.

Since there might be a lot of information on these elements, I wanted to create a widget for that side-tab and in a sense parent it to my main UI.
I can of course just create the widget and add it to the viewport on eventBeginPlay on my enemy-actor, but then how would i align it to where I want it to be? can I pre arrange my sub-widgets in my main UI in a vertical Box and then possess it?
I have currently no Idea how to handle this.

Unrelated bonus question: Is there a node that returns the ID of the Actor? Basically the ID I would have to feed into the get-Array node when i work with the “Get All Actors Of Class” Node?

Im pretty new to this, so sorry if my questions are formulated weirdly.


There are a couple of ways to do this.

If there is a fixed limited number of these widgets that you want to be able to use, then create a vertical box, add several of these widgets to the vertical box, and set their visibility to collapsed. Each time you want to “add” one, go through the array of these widgets to see whether it is visible, an when you find a collapsed one, make it visible and fill it with the information you desire.

If there’s not a fixed limit, another way to go would be to create a scroll box that goes on the right hand of your screen, then each time you want to add one of these newfangled widgets, create it and add it to the scroll box. When you are done with it, remove it from the scroll box (remove from parent).

Those are the general concepts.

Thanks for the answer!

Yes, it is supposed to be a fixed number. I drag and dropped my child-widgets in my main-HUD.
Since i see no way to edit each child-widget uniquely from my Main HUD, I gave them a variable “EnemyOwner” - an Enemy ObjectReference.
That way they could gather all the information from whatever enemy I feed into that variable.

On paper that works, but I still struggle when it comes to binding a specific enemy to a specific child-widget.
In the screenshot you can see a couple of actions I call on beginPlay on an enemy.
The child-widget successfully 'connects’to my enemy, but as of right now of course all enemies I spawn try to connect to child-widget number 0.
With this method I would need an unique int from each enemy-object starting form 0 (so that i.e. ‘enemy 2’ could posess ‘child-widget 2’ and so on.)

If that method somehow works i could perhaps simply collapse my widget whenever EnemyOwner is not valid.

But maybe the basic Idea of my approach is flawed aswell.
What do you think?

I’m unclear about why you can’t edit the child widget from your Main HUD, which I assume is a custom class.

Let’s assume your Main HUD class is called “BPMainHUD.” For each child widget that you have drag-and-dropped into the BPMainHUD class, make sure the “IsVariable” box is checked in the Details pane associated with that child widget in the BPMainHUD Designer window. You should now be able to access each child widget as a variable in the BPMainHUD class.

Yes, thank you.

When I asked I did not know how to access or assign the variables from the Parent Widget.
But I have found it, and everything works as intended.

Kind regards