Hi all,
My goal is to modify an object based on values received from an [FONT=Courier New]HTTP GET.
I have successfully triggered the network event in a basic FPS game by exposing my [FONT=Courier New]UFUNCTION to the Blueprint editor.
I have successfully made a callback to a static function of this [FONT=Courier New]AActor descendent, “[FONT=Courier New]ATurtleFarts”.
I can even successfully [FONT=Courier New]OnProcessRequestComplete().BindUObject() on the member method, not just a static class function.
All of the parameters arrive as expected in ThisOnResponseReceived() except that [FONT=Courier New]this is set to what appears to be an invalid memory location. All of the variables are invalid or appear to have random values (even the ones I set to 0 in my constructor).
UCLASS(Blueprintable)
class ATurtleFarts : public AActor
{
// ... snip ...
void ThisOnResponseReceived(FHttpRequestPtr request, FHttpResponsePtr Response, bool bWasSuccessful);
}
The relevant .cpp function bodies are:
void ATurtleFarts::ThisOnResponseReceived(FHttpRequestPtr request, FHttpResponsePtr Response, bool bWasSuccessful)
{
UE_LOG(LogTemp, Display, TEXT("Response Received by a Turtle object:"));
FString msg = Response->GetContentAsString();
UE_LOG(LogTemp, Display, TEXT("%s"), *msg);
ATurtleFarts:DeserializeJSON(msg);
}
int ATurtleFarts::RequestHeartBeep()
{
UE_LOG(LogTemp, Display, TEXT("Requesting heart beep"));
FHttpModule* Http = &FHttpModule::Get();
TSharedRef<IHttpRequest> Request = Http->CreateRequest();
Request->OnProcessRequestComplete().BindUObject(this, &ATurtleFarts::ThisOnResponseReceived);
Request->SetURL(TEXT("http://url-goes-here"));
Request->SetHeader(TEXT("User-Agent"), TEXT("X-UE4-TurtleFarts"));
Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
Request->SetHeader(TEXT("Accepts"), TEXT("application/json"));
Request->ProcessRequest();
return 1;
}
Breakpoints work, there are no compilation warnings, and the game does not crash.