[Question] I can't find this anywhere... Displaying player's extra lives as image(s) in UMG?

I'm developing a game and have been really sinking my teeth into the health/damage/death/lives logic this week. Everything is set up in terms of health and damage, health bars are working, attacks are working, etc. I just cannot, for the life of me, figure out how to display the number of extra lives a player currently has as an image or multiple images in a corner of the screen.

Here's a probably-entirely-unhelpful screengrab of my Widget currently. Health bar works, image doesn't draw to screen.

If someone could point me to the proper documentation, youtube tutorial, Learn Tab project, or even a particular setting that might get me going in the right direction, it would be much appreciated.

Posted Feb 22, 2016, 6:04 PM UTC

110
SoveranceDev•

The image should draw by default as you have it configured. However, the anchor appears to be located incorrectly - you'll probably get better results if you change the anchor to the bottom left corner.

The other deciding factor here is that you have a function bound to the brush. What is in that function? Your real answer is most likely in there.

1
offset_filterOPIndie•

The function is garbage, I was trying to use it to find int_P_lives, but unsuccessfully.

1
SoveranceDev•

Well that function will overwrite the properties of the brush component it's bound to. Unless you're setting the image of that brush inside that function, it will end up returning an empty brush and nothing will appear on your screen.

If it's garbage, you should unbind it from the component.

1
offset_filterOPIndie•

Did so, and that's working, but it just draws an image no matter what the condition of int P_lives. Which makes sense, because there's no reference to the lives integer. Just need to know where to reference that to make it draw multiple images depending on the INT value.

1
SoveranceDev•

What I'd do is create a slate brush variable in your widget, and then set this variable to update your widget using the bound function.

Now, wherever you're setting P_lives, you can do a switch on int and update the slate brush variable in your widget to whatever image you need it to be.

1
Exterminatio•

Hey there. In your shoes, I would do it via Grid (just add it as you would add any vertical box), that contains your custom user Widget. This widget could be f.e. border containing hearth image as background. So, you have 1 row and 5 columns grid f.e. (if you know for sure what's the max number of extra lives). Means you have 5 user widgets inside. If you have 3 extra lives - show first 3 widgets, hide 2 widgets. etc. (numbers of widgets to show and to hide are based on grid columns) :)

1
offset_filterOPIndie•

Still trying top get the hang of UMG. So I've got my grid (horizontal box, anchored to bottom left), and I have a border object displaying my heart image. I've added 5 column elements and 1 row element. I don't understand what you mean by f.e.

How do I add the heart/border widgets to the grid?

1
Exterminatio•

Sorry about my specific way of speaking english. f.e. means for example. You can find Grid Panel in your Widget in list of widget components. https://docs.unrealengine.com/latest/INT/Engine/UMG/UserGuide/WidgetTypeReference/index.html After that create a new User Widget. Remove Canvas Panel in it and place Border as top of Hierarchy. Change brush image of that Border to any of yours. In your 'main' widget, get a reference to Grid Panel and add 1 User Widget per live as Slots of this Grid Panel, using numbers of lives (in foreach loop probably) as numbers of Slot column. Sorry, can't access Unreal Engine right now, so I'm writing it all by memory.

1
offset_filterOPIndie•

I like this idea but it will only work if I have a max number of extra lives. Will still play around with it and see what I can do.

1