UMG/HUD Elements Being Redrawn?

I’ve put together a simple UI that updates a counter when an action is completed. When the actor is destroyed, the level restarts. What I’m noticing is that it seems the HUD elements are getting redrawn? I tried checking for the presence of the HUD before, but it didn’t seem to make a difference.

Any ideas what I might be missing?

I am a bit confused as to your intention but with the current setup it makes sense that every time the level restarts you would see the UI appear again. You are currently creating the UI on BeginPlay which fires every time the level starts.

If you check out my attached picture “UMG1” you’ll see that there is text getting drawn over existing text. What I would like to happen is every time the player dies and the level restarts, that the counter goes back to 0 and begins counting up each time it’s incremented. It currently does that, but it also looks like there is another UI element that is being drawn on top of it, and causing the issue.

I did see that image but was very hard to understand what it was.

It sounds like you are opening a new menu every time you try to increment your number. Instead open it one time on BeginPlay and then call a function on your widget to update the specimen count.

  1. On BeginPlay: Create your widget and add it to the viewport
  2. On your widget have a function for setting the number of specimens.
  3. In your player controller/Level/GameMode (whereever your game logic is): Every time the specimen count needs to be updated, call the SetSpecimen function with the new value.

Hmm, I’m only creating the HUD widget on event begin play, and follow the steps you’ve outlined. The counter works the first run through of the level, but once your pawn dies, and the level response, there are multiple elements being drawn. One that increments when the specimen incrementing logic is called, and one that just sits at zero. Do I need to destroy the hud or something before reloading the level?

Is the event begin play part of the level Blueprint? if so it’s going to get called every time you load the level and add the BP Widget to the Viewport each level load.

UMG widgets added to the Viewport are persistant. Levels are just things loaded up and do not muck with the Viewport itself.

Before you load the level on a restart you can remove from Viewport all of your existing UI so it will rebuild it on the next load and not overlap. Alternately you can cache these elsewhere on something that does not reload and just keep the reference to the UMG Widgets as you add them the first time and reuse it.

The event begin play is part of a pawn actor.

I will try removing the existing UI from the viewport, what’s the function for it? All I can seem to find is “add to viewport”

I did not think a menu would survive a map restart. What are you calling to restart the level?

You may need to clear the menu on End Play.

I think it would be better to put the create widget part in the event begin play of your HUD blueprint instead of your pawn blueprint. That way the widget is created only once, instead of being created every time your pawn respawns. At event end play in the HUD, you can remove the widget from viewport as RimmyD mentioned. You can use ‘Remove from Parent’ on the widget to do this.