Download

Cast to - a widget help

I’m brand new to UE4. I’ve been working with it for a few weeks now.
I’m trying to understand a basic concept. Cast To.
I get the over-all idea of it. The execution and why things fail seem odd to me.

When I Cast to, say, BasicWidget, and try to get a variable, it fails. I have to add Get All Widgets of Class, then pull off of Found Widgets and use GET. THEN I can cast to BasicWidget. Right?
It seems to even need to have BasicWidget listed under Widget Class.
I think you can make a variable reference to the widget and use that instead, but

Is there a second way to use Cast To BasicWidget that doesn’t mean it’s referring to the widget?
How can I use Cast To BasicWidget without filling that info in??

Do you add the widget to the viewport somewhere? Usually what I do is collecting most of the widgets in one layout (Widget Blueprint), and inside my Player Controller I use the Create Widget node to create the widget on startup, and then store the reference in a variable. Now I can cast to my player controller, get that variable, basically from everywhere. That’s how I access my widgets most of the times. If you want I can post a screenshot of my widget setup.

So what you mean, I guess I didn’t explain I kinda know? In my pic it would be the 2nd example. (Which usually doesn’t work for me)
The bottom example. The Place a new Node
Can a different node be made other than the reference to the widget??
What are all the things that Object [Select Asset] can be when casting to a widget?

There is no such node to get a cast for a widget in UE. Here is a widget setup on the Player Controller, inside a function called CreateHUD. However, technically it is just a widget blueprint, not a HUD blueprint - used usually to help initialize the current game mode.


Notice the widget blueprint variable called HUDReference. Each time I want to access something from my widget user interface layout I make a cast to the player controller, get the HUDReference variable, then have full access to my widget.

Alternatively you can also add for instance a blueprint to your player character, which contains a widget blueprint, and call that through a cast to your player character, then getting that blueprint. Said blueprint then contains a widget blueprint which could be toggled via an input button.

Notice below the attached Blueprint called Skillbook, and the InputAction event to call the function ToggleSkillBook, attached to the Player Character.

On that called blueprint the Toggle widget blueprint function, changing the visibility of the widgets main panel, to toggle visibility.

I’m not exactly sure what you mean. Get All Widgets of a Class [Widget Class] Load up > Get 0 > Cast To LoadUp, is exactly that. Am I missing something? Like, look in the png I posted. Right?

I don’t see anywhere in your images that you are casting to a widget. I see you getting references and displaying them.

I’m trying to ask a question I don’t know how to ask. I’ve tried to give a few ways of asking it. I’m not sure if you get me.
In my image, I pull off to the left of Cast to LoadUp; What options are there? Infinite? Just one? What will work there?

Okay so you want to access a variable in your widget. Now, after you’ve create the widget, and setup a reference to it, you are able to access said variable. The Get All Widgets of a Class node will work too, but this could be more complicated when you have more than one widget.

Here is an example where I access a widget panel from another widget, through the widget reference, setup on the Player Controller.

unit23, Thanks for your responses. I appreciate you trying to help.
With that said, PLEASE, do not respond to this thread any longer. I’m not sure why you don’t understand the question(s) I am posing. So stop. Please.

I need to know ALL of the options that can go in the red circle.

Actually, you don’t have to cast to your widget when using a “GetAllWidgetsOfClass” with “Get[0]” node. Here’s an example:

In this case, we’ve already got a necessary widget, so the “CastTo” is pointless.