So the situation is an actor bp. I don’t have any problem creating the widget from a begin play. However its in the getting rid of it when I need to that is not working out. Its a player HUD widget. When the player loses both lives it needs to remove so the continue widget comes up (not overlayed).
Before I need it I check with a branch the “P00 Lives counter” integer stored in the game instance. If this is 0 then it should remove the widget. At this branch if I use a greater than zero, the continue widget comes up fine but overlays the player HUD. However if I use a less than, and set it to either 1 or zero, the process seems to work, but it triggers after just one life is lost.
If it does, you might be adding more widgets than you think, and they become orphaned in the viewport, or the `Garbage Collection’ is unable to scoop them up. Count them on Tick:
If you have a destroy / respawn cycle here (if I am reading it right), I’d investigate the chain of events first. As in: at which point does the 2nd unwanted HUD comes to play? Put a breakpoint on it.
Another way to handle it is to not associate a persistent HUD with entities that get destroyed. Not sure if applicable here, perhaps you want/must create/remove widgets. But consider the HUD BP class - a framework singleton accessible from anywhere via the Player Controller:
It can be effectively used a widget manager. Think of it as of a hub for all UI related things that keeps tracks of widgets. It can also do some funky drawing stuff no other BP can.