Get Function pointer and UObject* from Dynamic Delegate

Is it possible to get the function pointer and object pointer from a dynamic delegate? Something like this:


FTestDelegate TestDelegate;


auto* Function = TestDelegate.GetFunction();
auto* Object = TestDelegate.GetObject();

You can try GetUObject() to get the object, but I don’t know a way to retrieve a function object. But if you just want to execute the function, why don’t you call Execute() on the delegate?

I have my own templated class for delegates in C++ and I was hoping to expose it to blueprint by taking delegates and extracting the function pointer, but I guess I’ll just save unreal delegates in addition to what I already have.

I quickly looked into the source code. The dynamic delegate macro defines a class, in which the function name is copied directly into the Execute function. So there is no way to retrieve to function, as it was never saved in a parameter.

For the normal delegates, this works through an interface and a huge amount of custom structs that implement this interface. One struct for one function type (lambda, UFuntion, raw c++, etc.) and different amounts of parameters. In the end the TBaseDelegate (which you create with the delegate macro) calls the execute function of the interface, which is implemented by the structs. But only the structs have parameters of the function, which vary in type depending on the function you passed by declaring the delegate.

So in theory, if you know the exact type of your delegate, you could cast it to the appropriate interface and check the needed parameter. But since these are created from templates and you need to know the exact types of function, return value and parameters, this would be far too complicated for me :wink:

Thank you very much for your help. I will stick to saving the delegates as is.