Hi All
Example.
I make a function to look after a widget for example. When you bind on click you have to make a Custom Event.
Is there a reason for it, or just not implemented?
Hi All
Example.
I make a function to look after a widget for example. When you bind on click you have to make a Custom Event.
Is there a reason for it, or just not implemented?
Yes there is a reason. Functions are functions and events are events.
Which means function can return some values, its kind of black box you put something on one end then other end delivers result.
Events are well events anybody interested in event can bind to it and react to event and its values.
One who created event does not care about results, or it would be quite messy to implement results coming back from every other blueprint that was bind to it.
Also if you want those results coming back anyway all you need to do is create events that work opposite way, ie send from blueprints that received initial event back to blueprint that called it.
Really there is no reason why its not implemented, it is just kind of tradition and logical thing to do those 2 types of procedures. And they are called functions, events and procedures because some beardy guy some 60 years ago called them like this.
PS.
I have bit better/shorter explanation:
Functions, you call them they do their black box calculations inside, and then they return value and you continue execution in same graph.
Events are functions that you do not expect to return back, kind of fire and forget function, you call them and they go on their merry way.
But sometimes itâs useful to call an event inside a function. Why canât I do that?
I donât see the need to call events per se, but because of some of the constraints of blueprints, calling an event in a blueprint can serve to make the blueprint a lot more readable, particularly in cases where you have nested for loops with breaks and such. I do miss the ability to clean up functions in a similar manner, instead of having to actually loop the exec wires back around it would be nice if you could just trigger the break event, etc separately.
I realize this is crazy old, but I wanted to give an example of why this would be useful.
If I have a function that does something black box like, but I want to register an event/bind to a delegate on something in that function itâs currently impossible. I still want my event to be a fire and forget thing, but I canât attach it to a delegate on my other actor without doing it in the event graph instead of in the function. If youâre dealing with just BP this isnât likely to be any kind of issue, but if youâre mixing C++ and BP it can be a big pita.
For example I have a C++ multicast delegate for when some event happens on my player. I have a separate actor that player can interact with and that separate actor needs to bind to that delegate when the player starts interacting with that actor. In order to bind to that event, I canât call a, âBind Delegatesâ function I have to call a âBind Delegatesâ event where I can then make my new event that Iâm binding to the delegate on my player. I canât have any of the functionality of functions if I do it this way. If part of my âfunctionâ needs local variables, I either need to add those variables to my base blueprint to access them in the event graph, or I need to have an event that gets triggered in the event graph so I can create a new event to bind to my delegate, then make a function for any part that needs local variables and call that from my event, so now I have a DoSomething event that is what actually needs to be called and a DoSomething function that does everything the DoSomething event needs to have done in a function but my DoSomething function shouldnât be called by anything other than the DoSomething event.
Itâs an arbitrary technical limitation that can make things way more confusing than necessary.
I get the separation is to prevent you from having events being defined inside functions, which is fair, but thereâs no way to store/reference events in order to register them on delegates inside functions atm, which is kind of silly.
You can declare / bind events inside functions, using âCreate Eventâ node. It lets you choose function to bind to it, and only shows functions in this blueprint with correct signature (identical to required signature)
You could also just set a bool outside the function and add a branch inside the function and once the branch gets through set the bool to false again.
Well you haven t been doing much porgramming thenâŚand even if it is an engine restriction, you got to be able to do event bindings on demands from outside your blueprint so inside functions
baaad design, bad !
just amazing, you avoided me loosing all my hair on this
if at least we could pass events by references or something âŚthanks dude !
Thanks for this
Remember you can have multiple Execâs going into a function
I echo the sentiment.
As for the âwhy would you do thisâ questionâŚ
use case
I have a setup options menu where a user can add a variable number of read files for the simulation to run. It is an open ended list Therefore I have the ability for the user to click a + button to add another file descriptor block to the setup UI so they can add as many as they need to set up the file names.
Well, those UI elements are all dynamically generated at runtime and no matter what system you use, something somewhere has to know either about who the message is going to (blueprint interfaces) or who the message is from (delegates/event dispatchers).
The run time generated elements arenât known at development time. I canât plug anything into the âtargetâ of these things in either case.
To keep things tidy, I have a function that does the âcreate a new UI element of this typeâ. Inside that Iâd add the binding to the incoming delegate. Until I found this discussion, I was having the devil of a time coming up with how to deal with that.
Create Event was the magic. Set its function to the shared function for dealing with the button click ( a button labeled - in my case) because they are all doing the same thing anyway, but they have to have each instance of the delegate bound to something at runtime.
So thank you to the poster who showed us the Create Event node.