how do you cast to widget

I looked up forums a lot but couldn’t find the precise solution I was looking for. Which node do you have to attach to the “object” port in the “cast to” in character bp? I tried the “widget object” and “widget reference variable” but neither worked. Thanks in advance.

1 Like

You can also use the reference directly without having to Get All Widget of Class. Store the reference in a variable when it is returned from the Create Widget node.

1 Like

Hi, thanks for your reply. I’m not very experienced with blueprints yet. Could you please help me understand what you meant by “returning” ? and where is this “create widget” supposed to be?

Okay, so … what happened to the other answer that was here?

I am sorry if I try to explain something you already know, but here goes:

5 Likes

Thank you for your patience and responses. I’ve no idea why the other answer disappeared. Anyway, I tried what you explained but I’m having trouble with “reference to widget bp.” The widget bp doesn’t provide “begin play,” so i had to set it like this.

PS: I’m using 4.13.2

Hey, I found an alternative that works perfectly. But thank you so much for answering patiently. I appreciate it. (ignore the booleans, they’re meant for other BP references)

Good work!!

A few things I was going to tell you, but didn’t get around to before you solved it:

In a widget you can use Event Construct instead of Event Begin Play. Construct is triggered every time the widget is added to the viewport.

Also the IsValid node is something I used in my example to verify that the widget exists in the gameworld. With a widget there is only a create node and not a destroy node which means that once the widget is created it will remain in memory. This is why it never closed the gate in one of your earlier attempts.

If you have a widget you want to display several times you could create the widget once, store the reference in a variable and then use that every additional time you display the widget. This way you don’t add the same widget to memory several times.

And of course: Good luck with your game!!

1 Like

Thank you very much! Lot makes sense now. Earlier I misunderstood the purpose of “isValid.”

Thnxxxxxxxx

Thank you

Check out video #25, goes over how to create a bunch of references including widgets.

2 Likes