So, I’m trying to pass a callback of type FHttpRequestCompleteDelegate as parameter to a function:
void UMyOnlineSubSystem::StartConnection()
{
IsConnected = false;
UMyGameUserSettings* settings = UMyGameUserSettings::GetMyGameUserSettings();
auto token = settings->OnlineToken;
FHttpRequestCompleteDelegate callback;
callback.BindUObject(this, &UMyOnlineSubSystem::OnCheckTokenResponseReceived);
checkToken(token, callback);
}
void UMyOnlineSubSystem::checkToken(FString token, FHttpRequestCompleteDelegate callback)
{
auto request = createRequest(token);
FTokenResult result;
request->SetURL(TEST_URL);
request->SetVerb("POST");
request->SetHeader(TEXT("Content-Type"), TEXT("text/plain"));
request->SetContentAsString(token);
request->OnProcessRequestComplete().Bind(callback); // <- Has no member bind
request->ProcessRequest();
}
Now, according to the docs, I should be able to do that:
[> Blockquote](https://docs.unrealengine.com/5.3/en-US/delegates-and-lamba-functions-in-unreal-engine/)
> Bind
>
>
> Binds to an existing delegate object.
>
> BindStatic
>
>
> Binds a raw C++ pointer global function delegate.**strong text**
BindStatic and all the others are accessible but not Bind, what am I doing wrong?
Is there an alternate way to pass the callback as parameter? I need to call this checkToken() method from 3 different places (in and out of the Subsystem).
void UMyOnlineSubsystem::OnCheckTokenResponseReceived(FHttpRequestPtr request, FHttpResponsePtr response, bool bConnectionSuccess)
{
UE_LOG(LogTemp, Warning, TEXT("TOKEN RESPONSE RECEIVED callback=%s"), *request->GetHeader(TEXT("Callback")));
auto callbackName = request->GetHeader(TEXT("Callback"));
auto callback = Callbacks[callbackName];
callback.ExecuteIfBound(request, response, bConnectionSuccess);
}
Basically I create a TMap and register the callbacks with a name into it, then I pass the name in the request header… This is very hackish and creates a lot of overhead but I didn’t find a better solution yet…
OnProcessRequestComplete() returns a reference to a FHttpRequestCompleteDelegate. So you can call BindUFunction/BindUObject directly on it or just assign your callback to it. I haven’t tried this but I think it should work.