My create widget hud makes 2!

I have looked everywhere and it is only this one place where it calls to create a hud widget, if i break the execute - there will be no hud in game, connect it again and there will be 2 huds! - I can see this because when my money goes down I can see there is another default money there.

This is my one and only create hud code:

you should probably rename that widget, because HUD is a standard type, so naming something MyHud implies its a type of HUD.

what blueprint is this image from? and what event is calling the create widget node?

hi,

this bp is from the character that we control

if you’re inside a character blueprint, you should use GetController, instead of GetPlayerController, because GetController will get the owner of the character, instead of getting the first player’s player controller. otherwise this would cause problems when you have a second player or AI characters.

characters are created and destroyed during gameplay, and some characters are not even controlled by players, they could be AI controlled, so its not a great place to spawn UI widgets from.

instead of spawning from the character, you should spawn widgets from your HUD blueprint or your playerController Blueprint, because these last for the entire time you are in the game, and they don’t get destroyed and respawned when your character dies.

also, if you want to have a money variable that a player owns, its a good idea to put it in a playerState, which is like a playerController that is used on clients during an online game. playerstates should own things like score, ammo, money, EXP, etc…

aha thank you, i moved create hud widget to my level blueprint and now it just spawns 1 :slight_smile:

but now the server doesnt have the hud widget anymore, but my client does

if its a dedicated server, it shouldn’t need to have any widgets. if its a listen server, the host player controller should spawn anything a client’s player controller would spawn.

can you post an image of the level blueprint where you spawn the widget?

How do I access gamestate or playerstate ? Where is it ? I see it everywhere but no one ever says how do i gain access to it ?

It is a listen server.

Level BP:

http://i.imgur.com/ol4RaPF.png

if you make a blueprint based on GameMode, you can set a playerstate and gamestate from within that blueprint.

and to access it from a pawn or character, you can use GetPlayerstate and GetGameState.

you are still using GetPlayerController, which uses a playerIndex. if you spawn widgets from a HUD, you can get the playercontroller that is related to that HUD using GetOwningPlayerController. each player in the game is guaranteed to have a single HUD attached to a single player controller.

if you want to spawn a widget in a level, you would be better off using a 3D WidgetComponent, because that would be located in the world for everyone to see.

Is this what you meant ?

I made a gamestate bp, changed world settings to use this gamestate bp.

I let gamestate create the widgets:

http://i.imgur.com/RW9dUS3.png

http://i.imgur.com/HCNvPZo.png

I also tried using a custom event:

http://i.imgur.com/MNPSmf4.png

my character:

http://i.imgur.com/x2SSpkT.png

(my character:)

Still nothing is working :frowning:

are you setting the character’s GameState reference variable at some point, using GetGameState? otherwise, that might be null.

have you tried creating the widgets from a HUD blueprint or player controller blueprint? creating it from a gamestate would require you to use postLogin to tell each playercontroller that spawns in to spawn a widget for its own screen, in which case its no better than just using eventBeginPlay in the playercontroller or HUD to spawn the widget.

and why does your widget own the money variable? isn’t it the players money? it should go in the playerState, along with any other score variables.

i would recommend spawning all widgets from the HUD blueprint. the hud’s purpose is to display 2D things on the screen, and each player has a HUD, while NPCs don’t have a HUD, so its the perfect place to spawn 1 widget for each player to have.

also, instead of using AddToViewport, you might want to use AddToPlayerScreen, just in case your game uses split screen at some point.

do you have steam ? and maybe you can look at it with teamviewer :stuck_out_tongue: ?

I put my hud widget in HUD bp and now I cant click on my hud’s buttons :confused:

i have other things i have to do for now, but keep playing with it, and if you cant get it working in a couple days ill try to help some more.

so for now i will leave this unresolved. good luck.