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.
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…
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?
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.
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.