How to send a float through an interface from PlayerState to a UMG.userwidget blueprint ?

I really need help as it’s been multiple hours I try to fix this problem.

This is the blueprint in the PlayerState :

This is the function in the interface blueprint :

This is the blueprint in the UMGwidget which is supposed to fire every tick since it’s supposed to receive the updated float each tick but actually never fire :

This shows how i made the reference to my UMG widget, i’m unsure if it’s set right :

This is a recap of my issue :

Any help would be appreciated, the problem being the event doesn’t seem to be called correctly.

What am I doing wrong ?

Before calling your Interface function, try connecting the “MainUIHudRef” variable to a Print String and see if it outputs anything.

First of, thank you for your help !

Indeed it seems like it input “None”.
Why is that ? I don’t understand.

How can I fix that ?

Alright, so are you setting any value to the MainUIHudRef variable anywhere before calling that interface function?

Your reply made me realized that I needed to do that.
I don’t know if the way I did it is the correct way but it works so far.
If there is a better way of doing this let me know I would be very interested :slight_smile:

Glad to hear that you found the fix. Well, one thing to keep in mind is that the “Get All Actors/Widgets” type nodes are expensive. Using it at Event Begin Play as you’ve done here is not going to cause an issue, but if you come across a situation where you’d have to call them a lot during gameplay, then it is usually better to store a variable that can be used directly.

Apart from that, I’d suggest making the HUD interface call from the blueprint where you created the widget. For example, let’s say you created your Main UI HUD widget in your Player Controller blueprint. Then it would be better to store a widget reference here and have all update calls for the widget to be done through this one variable. So you can just get your Player Controller, and either ask it for the variable or have it call the necessary function.

When you do it this way, you know that you have the right variable as opposed to Get All Widgets with Interface which can potentially provide duplicate copies if someone in your team accidentally created a duplicate Main UI Widget elsewhere.

I’m sorry i’m very new, I’m not sure how I would make a hud widget in my player controller blueprint, like in the screenshot is my best guess

But most importantly i’m running into another issue ! I’m trying to get the reference from an actor in the world to my mainUI_HUD and the get all widget from class doesn’t work.
But when I use get all actors of class and get MyPlayerState it works.
If you could explain to me why this actor can’t seem to do it, it would be very helpful for my understanding :slight_smile:

The actor in question :

My blueprint when using the get all widgets of class which says “None”

And when using get all actors of class and working good.

The Widget Component you saw in the dropdown list is actually a component for displaying widgets in the 3D world. Since we’re not interested in that, what we’re looking for is the “Create Widget” node, which I’m assuming you’ve already added somewhere in your blueprints. You can instead use that node to create and then store a reference to your widget in your Player Controller or Default HUD (not widget) blueprint, like this:

As you can see below the Event Begin Play, I have another event for updating the Score. Whenever the score is updated in some other blueprints, they call this event with the new score information. And we can then use the widget reference to update the UI with the new score.

So essentially, we’re saying that no other blueprints need to worry about widget references. All they have to do is tell your player controller blueprint (which is accessible from everywhere using GetPlayerController node) that some value has been changed, and the rest will be taken care of from here.

As for your actor unable to get a widget reference, it might be possible that the actor’s Event Begin Play is being executed before the widget has been created. So try adding a small delay of 0.2 seconds before calling “Get All Widgets of Class”.

Wow thank you for your explanations, I will try to emplement what you’ve said, that seems much more optimised.

As for the problem I had, adding a delay worked ! Thank you ! You saved me some badly optimised coding ^^

Happy to help :slight_smile: