Show Widget for specific clients

I’ve got a simply widget that shows player level and name (both stored in a save file), when starting up it sets it to hidden through a begin play (simply setting it to hidden on the details panel didnt work) and then, when a player gets in a sphere collision you’ve got attached to your pawn, it sets it to visible as long as it’s not yourself.

Simple, right? well, the problem is that if there’s more than 2 players things get messy:
Let’s say there’s 3 clients on a server, if client 1 gets close to client 2, they both can see each other’s tags but not their own, the problem is, once they get close, for client 3 the tags appear even though he wasnt even close to them.
How would I go about fixing this?

Hi,

How would I go about fixing this?

what behavior do you want?


Seems to me that currently you need to consider that the Overlap event will fire wherever the overlap has happened. So if it happened on client 1 to 3 it will execute on client 1 to 3 and for at least two of them IsLocallyControlled will be false and will therefore set the visibility of OverheadStats to true.

Hey, thanks for replying! I want the widget to show only for the players close to each other and not to some random on the map, so you could have 4 people next to each other seeing each other’s widgets but some other player in the other side of the map won’t see those widgets.

Obviously, I’d want it to set the visibility to hidden per player, so if one of those 4 people next to each other leaves all of the other widgets will stay there and will only dissapear for the one who left.

Sorry if I wasn’t too clear before!

If you want to show/hide it based on distance to the player, then I would go with a timer (a lot cheaper on performance than overlapping collision) that checks every X seconds the distance to the player and then hides/unhides it based on that.

So inside the EventBeginPlay you can set the timer

And I assume that you don’t want the player that controls a pawn to see its “OverheadStats”, therefore the IsLocallyControlled check so that the player that controls the pawn will not execute the timer.

And inside the function called by the timer

GetPlayerPawn with index 0 will be the local player pawn, and it checks the distance to this pawn. So if the local player pawn is closer than some distance to this pawn, it will show the OverheadStats of this pawn, otherwise it will hide them.

This completely solved it, not a single complaint, thank you so so much!!