Is there a way to make a button pressed in the widget blueprint to act as an event in the level blueprint?
Anything ?
Sorry to post again I’m just wondering if I’m asking the question wrong or is it a hard one?
The thing is that you need an access from the Actor to the Level Blueprint, but the Level Blueprint, as far as I know, isn’t accessible from wherever.
There is a workaround based on Event Dispatchers. Go to Your widget and add Event Dispatcher and call it, for example, MyEvent. Then simply call it when pressed the button:
In the Level Blueprint right after you create widget (RollerHUD here) bind the other event that will do what you want:
But I’m not sure if this is what You want.
I suggest to use GameMode for any global methods and events. You can have an access to the GameMode by simply using Get Game Mode and casting it to Your GameMode.
Hey there,
Thanks for the quick reply and sorry for being a complete dum dum.
Can you try helping me with one more time?
Thank you in advance.
In Your widget #2 add new Event Dispatcher (it is in My Blueprint tab) and call it OnButtonPressed. Then:
The OnButtonPressed_Event can be created by using “Add Custom Event” in blueprint.
In other words - You must think kinda backward. You have to make an event in the widget and bind an event from the level blueprint to the event in the widget. It works like delegates.
But I’m worry about that Remove From Parent and Construct nodes. Are you destroying Widget itself and create it again? You might lost the bindings then.
Hey,
Thanks for the reply and to answer your question, yes I destroy old widget when getting a new one. I could leave it hanging but how do I destroy all of the widgets at the same time later?
Also here is what happened with previously suggested solution:
Thank you in advance.
You must add an Event Dispatcher “MyEvent” in the “Terminal sendreceivedeliver” widget, not Level Blueprint (if I undestand it correctly the widget #2 is the Terminal, right?)
I’m not sure what do you want to achieve when you press the button. But maybe you should Call the “MyEvent” before destroying the widget.
I do have the event dispather:
Yes widget #2 is the terminal.
I mean the reason I have multiple widgets is because I wasn’t able to find a way to create a multi level menu in a single one so maybe that’s the correct solution here?
It’s hard to explain something when I don’t know how it should work… So I made a simple project with Widget and Event Binding to the Level Blueprint (compatible with 4.7.5)
https://dl.dropboxusercontent.com/u/1330338/EventExample.7z
I’m not into widgets and UMG yet, but maybe you can create some kind of parent widget and children in it?
Hey there,
Thanks for spending so much time with me. This solution does work for 2 stage menus but seems to not work with more. Here is your example back with added structure.link text
Thank you in advance.
You forgot to connect “Add to Viewport” with “Bind Event to secondwidget_button” in Level Blueprint
I’ve just got idea that you can do the light switching in other way. You can create a variable in the Game Mode that will hold an instance of the light switch. In Level Blueprint you can Set it into the instance of the light switch in the Game Mode. After that you should have access to the light switch from the Game Mode, which should be accessible from the Widget (Get Game Mode).
Well lol, ok! Thanks for helping me figure out the issue.
Also what happened was because I called another widget from the widget blueprint it for some reason messes up the dispatcher function in the final widget.
My solution was to make all widget buttons call only a dispatcher and use that to assemble my menus in the level blueprint. In a sense it feels like we’re missing the point of widget blueprints here but it’s the only way to interact with the level I was able to find.
Thank you very much and have a great day!