Displaying Player Lives as Sprites within Player HUD?


I once again find myself trying to do something I assumed would be simple, yet I am stuck :rolleyes:

I have been able to update the player hud for things like score/lives previously, but I’ve always used text. I wanted this time to have a little sprite, representing the player’s ship, and the number of these displayed would be the number of lives the player has (retro game).

I added a horiztonal bar to the ui widget and assumed I would then be able to loop round the number of lives the player has, adding a <insert something I do not yet know> here. Not managed to find what that something is yet.

I’ve search a little online but haven’t come across anyone doing something similar/tutorials etc.

Any guidance would be appreciated.

So far I’ve dumped a square brush into a separate ui widget, and I’m making that appear, but only one appears… so not sure if they are either stacking, or if I’m just doing this utterly wrong.

Some simple steps would be hugely appreciated or a link to a tutorial etc.

With kind regards,


Can you not just put 5 ( or whatever ) sprites in the horizontal box ( in images ), and just set the ones you’re not using to ‘none’?

Or does it have to be a flexible number of lives?


Thanks for the reply, appreciated.

I was hoping it would be more flexible than that.

The player controller has a variable for the number of lives, this defaults to 3. When initialized it will send a notification to the UI to update. The UI should then take the value its passed, in this case 3, and display that number of items.

During the game, events for losing a life / gaining a life, will use the same approach, sending a message through to update and with the new value.

That’s what I’m aiming for.

I should perhaps add, I’m ok with the logic/code for doing this, its just the UI aspect of it I’m not sure about… I don’t know what it is I need to use in order to display this. I’m assuming a sprite, but equally if I wanted to display a scaled down 3D mesh, that might be nice too… in all cases its the how I get something into the UI that’s the hiccup at that moment :slight_smile:

I think I might have done it…

These are the steps I took…

  1. Create image to represent player life (heart/ship etc)
  2. Import
  3. Create UI Widget
  4. Create SizeBox widget (I set the overrides for height and width to the size of my image 32x32)
  5. Add Image widget
  6. Set brush to use imported image
  7. Used the following code within my function which is called upon specific events (initialise/gain life/lose life);

It works, kinda, there are a couple of issues;

  1. None appear initially until I press a key (temp code) to alter the number of lives. I assume this is down to the execution order and that my bind for the event dispatcher is happening after the call to update it.
  2. The images are far too small within the HUD.

If there’s a more elegant solution which doesn’t involve the, somewhat harsh, ClearChildren, approach, I’m all ears :slight_smile:

I’m also a little uncomfortable setting the sizes for the images so specifically, whilst I’m not currently developing for multiple devices, this feels like it would be a bad approach.

Hi - sorry, only saw this by change ( good idea to quote :wink: )

I’m not much of a UMG officionado, but I think any kind of image is fine, why does it have to be a sprite?

It’s ok to set the size of things as long as ‘further out’ everything is encompassed in scale and position boxes. That will deal with moving things to the correct place for other platforms. You can always tell if you’re on the right track by resizing the viewport viciously. If you force it down to a tiny square, eveyrthing should go with it.

Aha, so replies don’t necessarily trigger notifications, thanks :slight_smile:

That was me just assuming, I guess it doesn’t and appears to work with just an image. Would be great to get that working now as a little mini version of the static mesh, they’d all look 3D then…

I’d not thought of trying that. The game itself (college project) is only going to be on one platform anyway, but the question was more generic I guess, as in I don’t want to start doing things wrong and getting into bad habbits…

Thanks for the reply :slight_smile: