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?