Haha it’s no problem, I’m happy to help!
Okay I might see the issue! I was wrong about the race condition: the OnResponseReceived() method should handle that.
I have two notes:
1: At the top of OnResponseReceived(), before you process any of the data, I’d recommend checking if bWasSuccessful is true, and if not then print the response code to the console. Something like this:
if (!bWasSuccessful)
{
UE_LOG(LogTemp,Warning,TEXT("HTTP request failed. Response code: %d"), Response->GetResponseCode());
return;
}
That way you’ll know if the response was not successful, and it won’t try to process anything unnecessarily. There’s always a chance that something could go wrong during the request, and this will help debug any issues there.
2: Are you calling the MyMethod node in Blueprints, or are you overriding it? Because I think that might be the issue.
If you’re calling it in Blueprints (e.g. attaching the white “execute” line to a MyMethod node), then that means you’re calling a new version of MyMethod, and not the one called in OnResponseReceived() (meaning it has no information).
What I think you might want – and forgive me if I’m mistaken – is to override it so you can extend the functionality of it in Blueprints. If that’s the case, you’d need to add the BlueprintNativeEvent specifier to the UFUNCTION()
macro.
Also, you probably don’t want PlayerName to be returned in Blueprints, but rather be a parameter that’s being passed in (the syntax for that trips me up all the time).
Your function definition should probably look something like this:
UFUNCTION(BlueprintNativeEvent, Category = "Http")
void MyMethod(const FString& id, const FString& PlayerName);
Edit: I removed BlueprintCallable to avoid confusion. You probably don’t want to be calling this method in Blueprints, since it’s being called when OnResponseReceived() finishes.
Edit 2: I made a mistake: It should not be BlueprintImplementableEvent, but rather BlueprintNativeEvent in this case (because we have a C++ definition). For anyone who may be reading this after-the-fact, you also want to add “_Implementation” to the end of the function in the *.cpp file, like the following:
void AMyActor::MyMethod_Implementation(const FString& id, const FString& PlayerName)
However, you do not want to add “_Implementation” in the header file. Intellisense will get angry, but it’s okay, it should still compile.
Then, in Blueprints, you can override MyMethod by clicking on “Override” next to the “Functions” bar on the left, like so:
And when you click on that, it should generate a new event on the Event Graph for you. When MyMethod is called on this Blueprint class (be it from C++ or Blueprints), it will now call this version of MyMethod, meaning you can add whatever logic you want.
One thing to note is that you should almost always be sure to include a call to the parent version of the method, otherwise you might accidentally completely override what you wrote in C++.
To do that, just right-click the Event node and do “Add call to Parent Function”.
Finally, you can start hooking up your nodes. I think you’re looking to do something like this:
Let me know if I got something wrong anywhere! I’d be happy to continue to help you debug this problem!