Binding delegate to interface on another UObject

What I’m trying to do is have other objects request UGlobalEventObject a binding to the OnGlobalEvent delegate, who would then bind the event of an interface they implement for them. The idea is I’ll simply pass a set of tags to the UGlobalEventObject from whatever object I need bound, and it will automatically bind it to the corresponding delegates based on the tags. Code is as follows:

 //.h
        DECLARE_MULTICAST_DELEGATE_FourParams(FGlobalEventDelegate, FGameplayTagContainer, const FGlobalEventStruct&, int32, bool);
        
        FGlobalEventDelegate OnGlobalEvent;
        
        UFUNCTION(BlueprintCallable, Category = "")
        bool RequestDelegateBinding(UObject* Requester, FGameplayTagContainer DelegateTags);
        
//.cpp
        bool UGlobalEventObject::RequestDelegateBinding(UObject* Requester, FGameplayTagContainer DelegateTags)
        {
        	OnGlobalEvent.AddUObject<>(Requester, &IGlobalEventInterface::OnGlobalEventReceived);
        	return false; //Placeholder so it compiles
        }

I get an error on the AddUObject line, saying

error C2664: 'FDelegateHandle TBaseMulticastDelegate<void,FGameplayTagContainer,const FGlobalEventStruct &,int32,bool>::AddUObject<UObject,>(UserClass *,void (__cdecl UObject::* )(FGameplayTagContainer,const FGlobalEventStruct &,int32,bool) const)': cannot convert argument 2 from 'void (__cdecl IGlobalEventInterface::* )(FGameplayTagContainer,const FGlobalEventStruct &,int32,bool)' to 'void (__cdecl UObject::* )(FGameplayTagContainer,const FGlobalEventStruct &,int32,bool)'

I’m obviously doing something wrong here, but I can’t seem to find any documentation on this, all I find are examples of how to bind a function to a delegate on the very same object, e.g.

OnGlobalEvent.AddUObject<>(this, &IGlobalEventInterface::OnGlobalEventReceived);

It argument incompatibility error, compiler can not convert the type, it might be confusing since incompatiblity is in function pointer type. If you look closer on both you can spot the diffrence

void (__cdecl IGlobalEventInterface::* )(FGameplayTagContainer,const FGlobalEventStruct &,int32,bool)

void (__cdecl UObject::* )(FGameplayTagContainer,const FGlobalEventStruct &,int32,bool)

The middle potion is expected name of function and in this case it is limited to namespace. This means the argument 2 expects function pointer from class related to UObject. Since you giving fucntion pointer of interface class function it has no relation to UObject and compiler rejects it. Not to mention there no guaranty that object implementing this interface can be UObject, thats why AddUObject don’t accepts functions from other classes then UObject related. Look on other options you have:

https://api.unrealengine.com/INT/API/Runtime/Core/Delegates/TBaseMulticastDelegate_void_Para-/index.html

You could try using AddRaw which you normally should use on non-UObject classes, problem with that is it wont do any blueprint call if needed (in most softer scenerio, since i never tried to use that with reflected interfaces on UObject, it may as well fail and crash, don’t
t know how it gonna react to it). There also option of using AddUFunction, since your interface function will be registered in reflection system, problem is it only accepts FName with function name.

Ability to bind UObject function using interface function pointer might be good idea as a suggestion to be posted in feedback forum, as there definitely missing gap, specially if AddRaw won’t work.

Thanks, I feared it might be an issue with the binding and the function being an interface function. I’ll try AddRaw, if it does not work I’ll find another way of doing it that doesn’t involve an interface function (and make a suggestion but even if accepted it’s going to be a while before it is implemented).

In fact, this is a bug in ue4, if u check about the source code in ue5,u will find the answer