So when i used to create buttons using actors , i would just have on clicked event in my level blueprint for this actor , and then i would be able to call all events i need in my game , but using umg i binded one of the buttons to an onclicked event , but in the function blueprint i don’t have any access to any function so what i am supposed to call ? i cant call events from level blueprint nor functions from my actors in the game!? so is there a way to do this ?
Call a custom event from inside the click function.
Cant since it cant see the custom events of toher blueprints or level blueprint.
Hi there, I ran into this same problem and Have figured out how to solve it. Or at least one way of solving it.
- Widget name is TestWidget
- Event dispatched is called closeMenu
- Image gallery is here [on imgur][1]
Widget Blueprint
Level Blueprint
In your widget blueprint, create an event dispatcher as you would any other. I called it closeMenu in mine.
In your level blueprint, or wherever you launch your widget, make sure you get a reference to the menu. It will be a variable of type UserWidget
Once you have this reference, you can cast it to your widget, in my case this was called TestWidget. Drag off of the ‘as Test Widget C’ anchor and call the ‘Bind Event to closeMenu’ function. Where closeMenu is whatever your dispatcher is called.
Attach a custom event in your level blueprint to the bind event call, and then have that even do whatever it is you want to do. In my case, it just prints out a string saying ‘clicked’
Hope this helps
Worked like a charm , but the problem is I didnt know about Event dispatchers , that will change so much in my game code , why wasn’t this introduced in UE4 tutorials ??
I was just wondering the same thing! Great job, Bergasms! Thank you for your help!
@Bergasms, Can you please help me out here ? In the first image, I understand that ‘Get On Clicked Event’ is a blueprint function that you have created. But can you tell me what the third node with the envelope is ?
Thanks a lot! That really really helps.! So, is the node below SET the reference to your widget ?
EDIT–
Also, if you don’t mind can you tell a word or two about the what the last node does in the first image ?
Thanks!
Heya, Bare in mind that this answer is from a couple versions of UE4 ago, so It might no longer be current.
Off of the top of my head, the node with the envelope is an event dispatcher. You used to be able to create them in your blueprints the same way you create variables and other stuff. An event dispatch is essentially just a message that can be sent out by the owner of the dispatch. So in this case, my Widget owns the closeMenu dispatch. when i call the dispatch (what is happening in the third node you asked about) the owner is essentially throwing the message out to whoever is listening for it.
In this case, my Level blueprint in the second picture is listening. Because the level blueprint created the widget (all the stuff in the second picture before the cast node) it has a reference to it. Once I do the cast node (middle of the second picture) my level blueprint knows that the widget is actually my custom widget called TestWidget. It also knows that TestWidget can send out a dispatch message called closeMenu so it can bind to that event and catch the dispatch whenever the test widget throws it out.
Hope that makes sense and isn’t too verbose.
The ‘Menu’ is indeed a reference to the widget. As of UE4.5 you don’t need the ‘cast to’ node anymore as the widgets come pre-casted.
The last node in that first image, the return node, is what is expected in all functions. When you bind a text widget your return node will have a variable of the text data type so that you can plug text right back into it etc.
Thanks a RumbleMonk I’m new to unreal and I’m trying to figure out things. Really helps!
Hello,
How and where did you get that “Menu” node?