How to make a widget blueprint that shows enemy/team icons over other players.
There are 2 ways to make this happen.
Assign some offset from the player position to display the widget above (typically X and Y are 0, Z is somewhat higher, around 100 could be a good start, but depends on your project scale). Then in the HUD class iterate through all the positions that are in the view range (take each, project to screen space, compare against your window size, you can safely cut out all that have either X or Y negative). Then simply set position of the widget to the one you found and fill the relevant data you want there (health, nickname etc.)
This is obviously just a first step, but once you do that you'll have it working, I've done something similar few months ago. What you could do next, and probably will is:
Center the widget. By setting the position to your pawn position + offset you'll make it draw the left corner there and the widget will look moved to the right. Calculate the widget width and height, get the middle point and offset again to make the point you choose. You may also just move the previous offset so it 'more or less' looks ok.
You have to create widgets on demand, because more players may show up on the screen. Having stored 100 widgets with 90 not used is a bad idea. Spawning them each tick is bad as well. You would need to store those already done and add more on demand. There are several solutions to this - you can add more if you have less available and keep them to not fragment the memory for example, but there would also need to be some boundary conditions. Might get tricky here, so start with simple.
Then there's the updating of widgets - visible player may get damaged thus forcing the update on health bar. For simplicity you can just set it each tick, but if there are many variables, you may want to check whether an update is needed or not. The widget itself may have a pawn assigned and as long as it is not NONE set it's own variables (each tick or not, each tick is simpler). HUD class doesn't have to do this. Doesn't need to know, even.
Depending on what you want, you may also want to have the widget shown when the player is off-screen, but the widget would be visible. Such case can be also calculated and simply widget rendered with it's left corner off-screen, the visible part will show up. Whether it's something you want or not is up to you.
The task is bigger than several screenshots would cover, but the simplest version - iterate through every player, assign widget, set position and data - is pretty simple.
answered Jan 13 '16 at 09:05 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here