Visibility of widget via event dispatch

Hi,
I have a UI button that I want to use to toggle the visibility of some text labels on and off . The button is sending an Event Dispatch (called Label Toggle) when clicked.

Each label is an actor instance in the scene with a widget component (so I can change out the text on each instance of the actor). I’ve set up the nodes to receive the event dispatch when the button is clicked, but I’m not getting the event to trigger on click.

I attached a print string after the Toggled Custom Event but that’s not showing when I click. I guess I’m not referencing the widget that the Event Dispatcher is on correctly.

As you can probably tell I’m new to UE Blueprints, have watched many tutorials but cannot work this out. Hopefully someone can tell me where I’m going wrong?

thanks!

try construct instead of preconstuct,

preconstruct is more to change default values

thanks for that, unfortunately using Event Construct hasn’t made a difference. Could it be anything to do with the fact the widget is loaded in within an actor as a component rather than added to the viewport via the Add to Viewport?

it could mean something is null, so validate your player controller for instance but is there any reason this button widget isnt just a child of the widget you’re trying to set visibility on?

I managed to get the player pawn to print a string when the button is called, so the event dispatcher is working that way, it’s just my blueprints that hold the label widgets are not hearing the call.

The set up I have is the on/off button is on a widget that is displaying as a HUD (along with some other buttons). Where as the labels are their own widget so they can be within the scene set to a screen space so they display as ‘2d’ but are anchored in 3d space.

From my (very!) limited understanding they couldn’t be a child of the button with that set up?

I’m sure there are plenty of things I’m doing wrong here, I thought perhaps I could try using and interface instead or an event dispatcher?

Appreciate your help here by the way!

so it looks like you’ve got a label widget and an ‘options’ widget

the label needs to bind to the options which means you do need to ensure the options are constructed first.

Or a better idea is to use the player controller. have the button call the event on the player controller and have the labels bind to that player controller.

OK cool, thanks for that heads up. I think I know what you mean by going via the player controller. Will give that a whirl and see if I can get it to work. cheers!

just a note to say your solution of going via the player controller worked a charm. thanks again! Been knocking my head against the desk for a couple of days trying to work through it, very pleased to have got a solution.

1 Like

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