Help with BP communicating with UMG HUD widget

I’m new to UMG and I’m still learning this new tool.
Basically I have a UMG HUD created in my character, I need this HUD to display variables from a BP spawned at run time.
Basically is a timing system BP, spawned at run time in the level blueprint, that should send to the HUD stuff like lap time and other race related infos.
How should I do this?

There are a few ways to do this, I usually set a reference to my blueprint when creating the UMG, and then from the UMG, I can access the blueprint’s variables.

Ok, so I should set a reference to my timing system BP to access its variables from my HUD widget.
How do I do this? My timing system BP is spawned at begin play from the level BP.
Do I need to create a timing system BP referenced object variable in my HUD widget?

Create bind on your GUI element and link them to your pawn/actor by casting Get pawn owner through the event graph of your GUI

Ok I will try as soon as possible.

First of all: LevelBlueprint for this is a bad place. The LevelBlueprint is not easy to be accessed by other Actors.
Better use the “GameState” class for this. You can always use “GetGameState” in your Widgets and access the Timer.
You can create your own GameState Blueprint Class and set it in the GameMode default classes.

In the GameState you can again use the BeginPlay Event and spawn the Timer Actor. Then you directly save the return value
of the SpawnNode to a Variable, so that you have the Reference you need. Then you can access it by getting the GameState,
casting it to your Custom GameState and accessing the variable.

You may also think about creating and saving the Widget in the GameState. Then you can pass the reference when creating the Widget.
Variables in widgets can be set to “Editable” and “Expose on Spawn” which will show them directly in the Create Widget node.
Same goes for Spawning Actors.

If I move the logic to Gamestate what happens when the race ends and the next level is loaded? Will it fire the logic, spawn BPs, etc, for every level that gets loaded?

Ok, Gamestate fires the logic tied to BEGIN PLAY at game start and when a level is loaded, I suppose it does as well every time a level gets loaded.

Yes, it will, as long as this GameState is part of the GameMode your are using for the other Maps (or as long as you use the same GameMode for every Level).

Moving the logic to Gamestate makes things much, much easier.
As you suggested I’m trying to move the HUD widget creation from the character to the Gamestate as well.
When I do that, though, the HUD shows the variables in the character such as speed, gear, health, etc. correctly but doesn’t show the ones from the timing system anymore.
With the widget created in the character it just works fine.

Are you sure that your Timer Reference is setup correctly? I can’t tell you what is wrong without
seeing what you are doing :smiley:

Yeah eXi you are right, I made some changes and now seems to work fine, sorry for being a pain in the neck a little. :smiley:
Basically I created the widget in the Gamestate promoted it to a public variable and then in the character got Gamestate, the widget and added it to viewport.
I hope this is the best/better way to do it.
Many thanks to you and the other guys for helping. :slight_smile:

Yes that is one way. Glad that i helped you (:

Is it possible to carry variables stored in widgets through levels?
I mean: I have my main menu created in the Gamestate by CREATE WIDGET, promoted to a public variable and added to viewport.
It contains ,among the others, a boolean variable I’d like to access when other level are loaded.
When I change level by node OPEN LEVEL with Absolute pin flagged (even without flag doesn’t change anything), the variable is equal to false no matter what.
In the new level I get the variable by GET GAMESTATE, CAST TO NewGamestate, GET Main menu, GET variable.
Is it normal?

Yes it is. Normally only the “GameInstance” class survives a LevelChange. You will want to save things that should be accessible in all Levels there
or semi save them in a SaveGame File. Otherwise you would need to step into Seamless traveling where you can define which actors should survive,
but i have no experience about this.

Sorry to bring this up after months but I’m not sure if it’s worth it to start a new thread.
Basically since then I used gamestate to spawn, assets, HUD, Player Pawn in the levels according to variables set in the main menu and then casted to gameinstance.
Basically when the new level is loaded, branches based on those variables fire a function not replicated which spawns the assets.
This works just fine until it is single player.
When I run the project as a client nothing works anymore: no assests, no pawn, no bots, only sadness.
I tried to replicate some custom events running those functions but no luck so far.
I googled to find some help and I found this topic: GameInstance doesn't support Switch has Authority? - Blueprint Visual Scripting - Unreal Engine Forums which puzzled me a bit.
Do I need to store elsewhere variables set by the main menu?
Thanks for the help.