Need help with passing delegates through other delegates.

Hey all, so I’ve been trying to wrap my head around this but couldn’t find a solution online.

I have two versions of the following code (neither of which work).

Version 1:




void UDNHGameInstance::PerformPlayerLogin(const FString username, const FString password, const FDynamicDelegateNoParams& OnSuccess, const FDynamicDelegateNoParams& OnFailed)
{
FString JsonString; // something

TSharedRef<IHttpRequest> Request = PostRequest("login", JsonString);

Request->OnProcessRequestComplete().BindUObject(this, &UDNHGameInstance::ProcessPlayerLoginResponse, OnSuccess, OnFailed);

Request->ProcessRequest();

}

void UDNHGameInstance::ProcessPlayerLoginResponse(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful, const FDynamicDelegateNoParams& OnSuccess, const FDynamicDelegateNoParams& OnFailed)
{

// ...]

OnFailed.ExecuteIfBound();

}



The above part won’t even compile. Gives me the error of:


 error C2664: 'void TBaseDelegate<TTypeWrapper<void>,FHttpRequestPtr,FHttpResponsePtr,bool>::BindUObject<UDNHGameInstance,FSuccessfulPlayerLogin,FWebReplyGenericSingle>(UserClass *,void (__cdecl UDNHGameInstance::* )(FHttpRequestPtr,FHttpResponsePtr,bool,FSuccessfulPlayerLogin,FWebReplyGenericSingle) const,FSuccessfulPlayerLogin,FWebReplyGenericSingle)': cannot convert argument 2 from 'void (__cdecl UDNHGameInstance::* )(FHttpRequestPtr,FHttpResponsePtr,bool,const FSuccessfulPlayerLogin &,const FWebReplyGenericSingle &)' to 'void (__cdecl UDNHGameInstance::* )(FHttpRequestPtr,FHttpResponsePtr,bool,FSuccessfulPlayerLogin,FWebReplyGenericSingle)'

Then, I tried changing things up a bit like so:




void UDNHGameInstance::PerformPlayerLogin(const FString username, const FString password, const FDynamicDelegateNoParams& OnSuccess, const FDynamicDelegateNoParams& OnFailed)
{
FString JsonString; // something

TSharedRef<IHttpRequest> Request = PostRequest("login", JsonString);

Request->OnProcessRequestComplete().BindUObject(this, &UDNHGameInstance::ProcessPlayerLoginResponse, &OnSuccess, &OnFailed);

Request->ProcessRequest();

OnFailed.ExecuteIfBound(); // this executes; tested via commenting out the other and vice versa

}

void UDNHGameInstance::ProcessPlayerLoginResponse(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful, const FDynamicDelegateNoParams* OnSuccess, const FDynamicDelegateNoParams* OnFailed)
{

// ...]

OnFailed->ExecuteIfBound(); // this doesn't execute :(

}



This version compiles, but as I’ve already commented, the delegate in the function where I need it to execute doesn’t seem to be bound.

I feel like I’ve really hit a brick wall on this one. Can someone help me understand what’s going on?

Did you try passing the delegates as copies instead of references?


 
 void UDNHGameInstance::ProcessPlayerLoginResponse(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful, FDynamicDelegateNoParams OnSuccess, FDynamicDelegateNoParams OnFailed) 

I have, but that didn’t do the trick either unfortunately. Perhaps it’s related to some engine mod I’ve made, or maybe it’s just not possible.

Either way, I have since switched from the model outlined in the thread to a more streamlined version, where each function calls upon a separate multicast delegate that is declared in the header. The downside is that there are now a lot of multicast delegates, but the upside is that classes that want to be notified of an event need not necessarily call the executing function and can instead just listen. An odd workaround, but it does work!