communication between 2 widgets not working

I’m trying to call a custom event i created inside my first widget, inside my second widget. The custom event makes changes to my first widget, but the code i wrote for it doesn’t give the right result, although it should?

widget 1 containing custom event

1

widget 2 containing the button, when clicked calls custom event:

the custom event doesnt do anything though? what have i missed?

Thank you for any replies

After creating widget, you need to add it somewhere, otherwise it’ll never be visible.

Either add it to an existing widget container (vertical box, etc…), or AddToViewport / AddToPlayerScreen for top-level containers.

I have already done so by adding it to a wrap box

sorry about the confusing nodes just pay attention to the create widget and add child to wrap box node, still doesnt work tho

But you’re not calling ShowImage anymore ?
Looks like this is not the same widget.
In the first post, this created widget is not added anywhere
image

Also, when creating widgets from within widget blueprints, use “Get Owning Player” node instead of “Get Player Controller 0”.

Thank you for your reply.

I’ll explain the structure of my widgets

‘lila’s chat widget’ is the widget containing the custom event (aka widget 1)

‘lila’s chat widget’ is created in a previous widget that has no relevance to the problem at hand

‘text photos widget’ (widget 2) is the widget trying to call the custom event ‘show image’ from ‘lila’s chat widget’ (widget 1)

sorry if i’m not understanding straight away what you mean, I am a beginner in UMG still

what do you mean? can you explain further?

No they are not, I am trying to calling the custom event ‘Show Image’ from ‘Text Photos Widget’ that does not own it by ‘creating widget’ to get a reference to ‘Lilas Chat Widget’, this does not work.

Hmm so you want to create LilaChatWidget from ContactsWidget, and then you want to access it from TextPhotosWidget ?

Right now you are creating two LilaChatWidget :

  • one from ContactsWidget, which is added to viewport but ShowImage is never called on it
  • another one from TextPhotosWidget, where you call ShowImage but it is not added to viewport

So instead of creating a second widget, you need to use the existing one.
The simplest way to retrieve it would be to use node “Get All Widgets Of Class”.

1 Like

thank you for getting back to me. I apologize for the late reply, this seemed to have worked I am now able to call the function correctly. I have one more issue that I think might be linked to what you were saying.

I am setting a variable that belongs to a widget called ‘Expanded Image’ from within my ‘Text Photos Widget’. Again i’m creating this widget then getting access to the variable and setting it that way.

On my ‘Show Image’ function, ‘Expanded Image’ Widget is added as a child to ‘Lila Chat Widget’ I do know I should use ‘get all widgets of class’ then I used ‘For each loop with break’ but I dont think this is right, the widget is not being added and nothing happens.

Thank you again for your help I appreciate it greatly as a beginner

You are calling ShowImage before creating the ExpandedImage widget, so in ShowImage the call to GetAllWidgetsOfClass finds nothing. You probably want to create the widget and set its SelectedImage variable, and THEN call ShowImage to add the widget into your box.

Instead of using GetAllWidgetsOfClass, you could add a parameter to your ShowImage function, and pass the created ExpandedImage widget through as parameter. This would be much proper.

1 Like

Thank you so much! it works, greatly appreciated :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.