How can I cast to a UMG from a pawn/character BP?

Hi,

Has anyone been able to cast to a UMG widget from a pawn/character BP? I just can’t work out the setup needed in order to trigger a custom event in the UMG in question.

Thanks.

Well, not casting… but I got GameState to use an Interface Message function to send text to a UMG widget that has a textfield. Just note the event receiving the interface call has to be in the widget Eventgraph, not in a function.
Using an interface you can do much the same things as casting data (well, so far as I’m aware).

I have a video showing it: https://www.youtube.com/watch?v=4iihWgt1lkY&feature=youtu.be&a

Cheers for the answer. I’d previously updated values on my UMG by changing values. e.g. a boolean in my pawn blueprint, and casting from the UMG to that value, then using the result to branch but it all has to be set to occur on the Tick Event which isn’t ideal, hence wanting to get Custom Events triggering.

From watching your video I think I’m just missing the Interface Message as the go between stage. Will give it a try this evening. Thanks :slight_smile:

Just been trying to implement this with no joy :frowning:

No matter what I setup, custom event or an interface event, it just will not trigger within the event graph of my widget blueprint.

I’ve tried watching your video several times and whilst you clearly know what you’re doing, you jump around a lot and far too quickly for me I’m afraid.

Probably best if I show precisely what I have working already:

(top image is my character BP, bottom 2 images are my widget BP event graph and function)

This does the desired effect of updating an on screen textblock to show how many times the RingHit event has triggered (which is fired by the player overlapping any pickup blueprint in the world).

As I mentioned though, this setup still has the widget checking this value every Tick which is what I want to avoid.

I’ve simplified this a lot for the sake of the screenshots, but I really need to get my head around how it can be handled in more complex cases.

Thanks for any extra help you can give.

What you can do is take the Return Value of the Create Widget node and right click it to get the “Promote to Variable” option. Then that variable can be used to get the Cast.

In my example I create the Widget in my Player Controller and the variable “HUD UMG Ref” holds a UMG Instance. You can pass information from the player controller to most other actors very easily.

I have talked with about using Tick with UMG and he says that it’s perfectly fine unless you have 10,000 things happening.

Based off of your image, the best practice would be to Cast To CharacterTest in the Ring Counter binding. Here is an example of how we print text:

Let me know if this helps you or if you have any questions.

Hey ,

Thanks for the response. It looks from your example that the only difference between my setup and yours is that you’re casting within the binding rather than the widget event graph (not sure that this makes any difference to when the cast occurs)

Whilst I appreciate that having this value always update may not be an issue, can you please confirm whether my original idea is actually possible - i.e. using a custom event within a widget that is triggered by another BP.

If it’s not possible then perhaps the option to create these custom nodes should be disabled within widgets; unless of course there’s another purpose for them that I’m not picturing.

Many thanks :slight_smile:

You could use custom events inside the graph, but I am not sure they are working properly right now as UMG is very experimental. Are you having trouble with Custom Events in widgets?

you’re casting within the binding
rather than the widget event graph
(not sure that this makes any
difference to when the cast occurs)

It does make a huge difference, not in the casting itself, but when the casting is done. The binding will essentially update in a “tick-like” way using the Slate redraw code. It is more performant to use the binding technique. I hope this helps, let me know if you have any questions.