Widget communication

Hi guys, I’m working with Bluprints.
I’ve got two different menus (widgets) and i’m trying to set a couple of variables for them to share.
If I create the variables in one widget i can’t access to them from the other widget (that i know), and I can’t place them in the level cause i’ll eventually change the level.

I’ve tried to create the variables in the HUD, and i can access them from each widget with Get Player Controller -> Get Player HUD -> CastToMyHUD -> Get/Set the variables.
The problem is that this internally creates a local variables on each HUD, so when i access to those HUD variables from the other widget they have not changed, and I don’t know how to do it properly.

Any idea on this particular problem?
Thanks.

Have you tried using the GameMode or GameState as the place to store those variables? I think those are the places for stuff like Health or Score. If it’s an MP game, note that GameMode is only accessible to the server, but GameState is available to all clients. Hope that helps.

Not working :frowning:

“Current Resolution” is in FirstPersonGameMode, and i’m accessing this way:

Am I doing it wrong?

Create interface, that either sends over all variables or one intercface for each variable.

Decide what is source of those values. For eg for “current resolution” it will be player controller (each player can run different resolution).

So create interface with function “update current resolution”. Add this interface to all widgets that should know it.
Then “get all widgets with interface”, and call that function for each one.
Inside widgets function store value of “current resolution” into local variables.

Interfaces win here over event dispatchers, as you can give return values back to calling blueprint. Also you get only few widgets.

Dispatchers would be good only for sending to dynamically created actors, but then again all they do is hide “get all actors of class”+“for each loop”. And strip that return code. So unless you have something that may take long time inside called actor, interfaces win.

Ps. For interfaces to work you >MUST< have return value in return node. Else they will not show on function list, not sure if this is bug or feature, so we just add dummy return value that is boolean: “Epic#####?” and we set it to true or false depending on mood.

Oh, nice idea.
So you mean it should be like this?
interface.png
Interface


Widget

I’ve already added the interface to both widgets.

Oh forgot that on the widget i have to connect Resolution to Current resolution, it’s like implementing the function on each widget as I understand it, right?

yes it calls local (to widget) function that you call from for each loop. Also you do not need “Cast to widget_A”, so different blueprint classes can be served in same loop without casting to multiple classes. Interfaces are great, they help keeping order in blueprint code.

Biggest advantage of this is that you may have same actor belonging to different groups, and you do not need to have array that keeps their lists.
You just add that resolution interface to actor types that should be aware of it, then for example “take damage” to all actors that should be aware of some AOE damage. And some actor may have both interfaces (so will be on both lists).

I think I’m so stucked T_T
I’ve set the Current Resolution in one widget, how do I “Get Current Resolution”? I don’t know how to implement that function. The purpose of all this is to send a variable from on to the other, and it can’t be allocated in the interface, so I have to place it in one widget, and can’t get it from the other one.
I’m sorry man.

I think that “slave” widgets do not see real resolution, only HUD (and player controller of player that created hud) have real screen resolution.
So you should read that resolution in player controller, then send to all widgets that need it.

Widgets are similar to child actors in blueprints they exist on top of hud (which is widget also) and that is connected to player controller that created HUD.
So best place to read resolution is in player controller, esp if you want make multiplayer game later, less confusion this way.

Thanks, it finally worked. I had already tried with the viewport size, but it was giving wrong values cause it wasn’t in Standalone mode.
Btw, is there any way to check if the game is being played in Fullscreen? can’t seem to find the way.