Hello, iam working on a Userinterface in Blueprint and have a hard time dealing with callbacks of buttons etc.
Is there any easy way to supply a delegate reference to a function via a parameter or any way to give my function something so i can bind events in that function?
It’s funny how there are some completely dead topics on this site isn’t it? I can never get anyone to give me answers related to either delegates or animation.
yeh this sucks the way delegates are right now is completely useless ill try and get this working in c++ maybe i can add a delegate reference datatype or whatever
You need to create an event dispatcher as the ‘variable’ you will store your function in. This is what you will call. Then, in the other class you create a custom event with the same signature you want to be called. get a handle to the first class and find the ‘bind to event x’ option. then pipe the delegate handle from the custom event into the bind node.
now when you call your function the custom event will be called instead.
Well, there is a way, and it is actually not that difficult. If you have a set list of functions that you are choosing from, and suspect you do, here is the way I would handle it.
On the event host, create all of your events.
Create event dispatchers for each event and bind them. You will likely need to do that event binding either in the construction script or in the event begin play script.
Create the function you want to call, let it take an int (or enum) as input
Inside the function, use a switch on int to send call the correct event dispatcher.
You can even use variations on this to bind/unbind events from event dispatchers and such. Up to you.
What if I don’t want to store the function, and just want to pass it into another function which calls it, calculates things and returns without storing it?
Yes, but you can’t do it using only blueprints: only functions created in C++ can accept delegate parameters. Blueprints can only create event dispatchers, which are multicast delegates.
For UI, you create a dispatcher in your custom widget blueprint. Then when you add that widget component to another widget, you can bind the events directly from the design view, just as you do with the built-in button component: your dispatchers are listed at the bottom of the details panel, with buttons that will create the event nodes for you.
I read through this and ended up using interfaces to implement a callback mechanism similar to passing a delegate.
You can view my workaround here: Building New Worlds - Nose to the Grindstone
I follow your code, but vs report an error said, Unrecognized type ‘FOnlineUserImageRetrievedDelegate’ - type must be a UCLASS, USTRUCT or UENUM.
When I remove the decoration(‘UFUNCTION(BlueprintCallable, Category = OnlineUser)’) above the function RetrieveThumbnail, the project can compile and no error.
I wonder how can you compile those code withour error
why are they called event dispatcher since one sets them up to receive events as far as I nderstand
[edit:jeee this forum sucks to reply to the right person]