Save UI Element Reference on associated Actor and restore it

So I have created this Widget for my Barracks that allows the Player to train new Units and also Queue them. The Barrack is then training one Unit at the Time. This works fine.

When I close the UI for the Barrack I remove it from the main HUD. Because of this I need to save the Content of the Recruitment Queue and restore it when the same Barrack is clicked again. This is done in the “RecruitmentQueue” Array.
To show the Queue in the UI I create a Widget “UnitRecruitQueueCard” in the Horizontal Box “RecruitmentQueue1” for each element in the “RecruitmentQueue” Array.
Once the Unit is spawned I remove this Unit from the Array and the Widget.


Also this works. The Problem I’m having is that once the UI with the content is restored that the remaining Units in the Build Queue do get removed from the Array but not from the Horizontal Box.

My guess is that this is caused because the Horizontal Box “RecruitmentQueue1” that is created when the Barrack is clicked again isn’t the same refrence as when the Widget got created the first time.
I tried to save and restore this refrence in the same way as I save the “RecruitmentQueue” Array but then I don’t get the Horizontal Box “RecruitmentQueue1” in the UI at all when the Barrack is clicked again.

Here is a short clip with the Menu open.


And here is a clip what happens when I close and reopen the Menu while Units are being recruited.

I would better add unit remaining time in the queue array. And make widget decide own self about his UI unit destruction.

if in case it is needed to add special events (freeze unit time or slow it down) I would also add some state to each queue item in the array.

in case “runtime” changing between widget and controller, I would add some interface in the widget (if any UIs with this interface exist, call interface event in them).

Between writting the Post and your answer I had a similar Problem with “remove from Parent” where I solved it by moving the logic to the child but I didn’t think of using it here as well.

I tried to do the same thing here now as well but I couldn’t get it to work.

What exactly do you mean by this? How do I do this?