UMG Draw duplicates for every player


I have this in MyCharacter. The hud itself is one giant button, when you click the button, it sets the button to hidden. When playing with one player, this works as intended. If you launch with 2 players you have to press the button twice, and with 3 players you must press it 3 times. This happens also if you play solo but do a level change, it will draw a new hud again on travel.
How can I stop this from happening? It is causing major problems in my game.

If that is in your ‘MyCharacter’ then it will be shown once for every ‘MyCharacter’. What you probably need to do is, spawn the widget in your HUD class.

I thought the HUD class was from before UMG was implemented. Thank, I’ll give this a shot when I get home and let everyone know how it goes.

Yeah it’s better to create UMG widget in the HUD, but you still can do it in the character BP by using the islocallycontrolled node.

This fixed the issue, as did islocallycontrolled. But I lose the ability to reference the hud on levelchange. I establish the reference on create widget -> set variable “active Hud” to the return value. I guess I’ll have to put it in the savegame?

For now, I’m using the isLocallyControlled on the Character and I added a remove form parent to the start game button. I found that this only removes it visually, the hud actually still exists. For example, if you make a function in the widget that plays a sound when you press it, and add an input in the character that calls that function, and an input that removes the current hud from parent, the result is pressing 1 removes the HUD and pressing 2 still plays the sound.
Not sure how important that is. But, if the server loads a new level it will draw a 2nd hud since the original is not removed on level change. This is a headache. :confused:

Edit: I suppose running a remove all widgets from parents on beginplay before the new ones are drawn would work, but get all actors of class does not pickup widgets and there doesn’t seem to be a way of referencing a specific widget after the level has changed.