Bind delegate with function pointer


I just ran into an issue with delegates and thought it would be good to let you guys know.
So there is the “AddDynamic” macro which allows you to bind an object with a function to a delegate, which works just as expected when you do for example this:

MyDelegate.AddDynamic(this, &MyClass::TestFunction);

But now if you want to do that with a function pointer for example like this:

void MyClass::MyFunction(void (MyClass:: *FunctionPtr)())
    MyDelegate.AddDynamic(this, FunctionPtr);

It will cause a crash with an error message which looks something like “FunctionPtr is not a member function of…”. The reason for this is that the AddDynamic macro uses the FuncName input to set the function name in the __Internal_AddDynamic function, so in this example it would call:

__Internal_AddDynamic(this, &MyClass::SomeFunction, TEXT("FunctionPtr"));

Of course you can do workarounds for this like adding the function name as a string parameter to your bind function and call __Internal_AddDynamic directly, but it would be awesome if there could be a better solution for this.

By UE4 convention you should hold delegate as public varable as delegate provides more functions then just binding and they can improve over time too.
The function you trying to bind is part of MyClass?

In the specific case where I would have wanted a functionality like this is my menu where I have a AddButton function and it should look like this:

void UMyWidget::AddButton(UTexture2D * Icon, void (UMyWidget::* FunctionPtr)())
    // Create button bla bla
    NewButton->OnClicked.AddDynamic(this, FunctionPtr);

But because of bementioned problem I have to bind the delegate for every button individually. Of course this is not a big problem, just trying to point out this small inconvenience :wink:

Sorry for the resurrect.
I am doing exactly the same. Did you solve it somehow?