Need help in accessing other Widget Functions

Hi,
Can anyone please take a look at the pics below and tell me what I’m doing wrong and what I need to do?
I’m just trying to access a function in another widget bluprint.

I’ve had problems trying to reference objects in other bluprints in the past, but I’ve usually avoided it by using Get All Actors Of Class with For Each Loop, which usually works for me. But when I try doing so similarly with widgets using Get All Widgets Of Class it doesn’t seem to work. Therefore, I’d like to know how to reference things properly.

You have 2 widgets, MainInterface and wGather. You created both using CreateWidget node. Think about the place in your project (the specific blueprint), where you did that. The reference will be there.

Generally speaking, as your project grows, you need to organise your code as logically as you can. Otherwise you will not remember where things are. Consider creating widgets (or just storing their references) in a single, easily accessible location. GameMode is a decent candidate, so is the GameInstance, a custom HUD class is not bad either.

Whenever you create a widget, access the GameMode and store the reference there, for example.

From my own personal experience, I tend to create a separate actor and make it responsible for handling widgets and their communication. While this may not be always necessary, it’s a workflow that has worked for me well.

A lot of (mostly beginning) folks swear by the GetAllActors/WidgetOfClass nodes, but not only is this approach ham-fisted but also potentially dangerous as you get an array of objects in what has always seem to me a pretty random order.

Anyway, think of the place where your created your widget and its reference. You need to access that location.

I created the widget in the W_Gather Event Graph.
I pulled a promoted variable from the CreateWidget node in the W_Gather widget Event Graph, and then in MainInterface widget Event Graph I created a reference variable for the W_Gather widget, as shown below.

It gives be a blue highlighted note and an error saying ‘W_GatherReff’ is already a ‘W Gather’, you don’t need Cast To W_Gather .

That’s not how things work, sorry.

In the first screenshot you’ve just posted, you are creating a wGather widget while inside another wGather widget - isn’t that confusing? Or do you need 2 instances of the same widget?

In which blueprint do you create the original wGather widget? Or is wGather a custom widget you manually added to the MainInterface in the Designer?

There must be a place in your project where you create the 2 widgets initially.

Cast is only used when you’re not certain what kind of object it is. No need to cast a direct reference of the correct type. (look at your character casting, for example: Get a generic Character and Cast it To the specific one that you’re using in your project)

Yes, I agree it’s confusing. I know I am clearly going about it the wrong way.
When you say “In which blueprint do you create the original wGather widget?”, do you mean the very first place I Created the wGather widget in an Event Graph, or do you mean in the widget’s Designer, or do you mean somewhere else?
I created 2 widget blueprints (MainInterface and wGather) in the content browser, I designed the widgets in their respective Designers. In the wGather widget Event Graph, I did a Create Widget for wGather, and thats the only Create Widget for wGather in the whole project so far.

The OnClicked Event for the green round button in MainInterface takes me to its Event Graph, and from there I am trying to get another widget to pop up from within the wGather bluprint, where at the moment, in its Event Graph, there is only one Create Widget for wGather.

the very first place I Created the
wGather widget in an Event Graph, or
do you mean in the widget’s Designer

In the EventGraph. It’s also were you keep the original reference to it, most likely.

In the wGather widget Event Graph, I
did a Create Widget for wGather, and
thats the only Create Widget for
wGather in the whole project so far.

This might be the confusing bit - you are trying to create wGather inside its own EventGraph :slight_smile:

Have a look at this:

I create 2 widgets in my GameMode (a class that is accessible from anywhere in the game, we’ll get to that):

I promoted both returns to variables - this way, the GameMode now stores a reference to each widget - the references are also of the correct type, so they do not need casting.

Now, wherever in the game I am (it can be in any of the widgets, too), I can do something like this:

Essentially, the GameMode is storing the references to those 2 widgets and any blueprint that can access the GameMode can also directly access those widgets. They can talk to one another, too.

Think about it as the object that serves as a communication hub for the data and creates connection between parts of the game.

Let me know if this clarifies things a bit.

The OnClicked Event for the green
round button in MainInterface takes me
to its Event Graph, and from there I
am trying to get another widget to pop
up from within the wGather bluprint,
where at the moment, in its Event
Graph, there is only one Create Widget
for wGather.

In this case you should let the MainInterface create the widget, no problem with that. Create it in the MainInterface’s OnClicked Event and store the variable.

Thank you so much!
All this time I’ve been trying to connect references to the cast’s object node(where you have Get Game Mode’s connected to).
I’ve created the wGather widget in Game Mode and stored the reference there. And I am able to access it there from the MainInterface Bluprint.
I have also tried creating the wGather widget in MainInterface and stored the reference there, and from there I can talk to wGather to play the widget animations I have there.
So, both ways worked.
Thank you for clarifying all this for me.

Great! And yeah, both will work!