Unreal Crashes on accessing a method in normal class from an Actor class.


Goal - Implementing Http functionalities in an normal cpp class(not an Actor) and access those functionalities from an Actor class.

i.e : TestHttp.cpp(Normal Class) SCRIPT:1

void ApiManager::Login(FString userName, FString password)
fHttpModule = &FHttpModule::Get();
Variables* VariableClass = new Variables();
FString url = VariableClass->BaseApiURL() +VariableClass->ApiSignin();
TSharedPtr<FJsonObject> session = CreateJson(userName, password);
FString OutputString;
TSharedRef< TJsonWriter<> > Writer = TJsonWriterFactory<>::Create(&OutputString);
FJsonSerializer::Serialize(session.ToSharedRef(), Writer);

TSharedRef<IHttpRequest*> Request = fHttpModule->CreateRequestPtr();

Request.Get()->OnProcessRequestComplete().BindRaw(this, &ApiManager::LoginResponse);

CallFunction.cpp(Actor Class) SCRIPT:2

void ACallFunction::BeginPlay()
ApiManager* tpm = new ApiManager();
tpm->Login("abcd", "apple");

if the login function being accessed from an actor class unreal crashes
and it throws an error at -> TSharedRef<IHttpRequest*> Request = fHttpModule->CreateRequestPtr();
But the same works fine when the HTTP functionalities were created in an Actor class and called from the same Actor class.

did anyone faced similar issue ?

Are you sure that the fHttpModule is actually valid? Looks more like ‘fHttpModule = &FHttpModule::Get();’ fails to get the module and so it is NULL? I don’t think it is because it is accessed through an Actor as it seems to find and call the function fine if it is getting to that point?

Hi, Thanks for your response.
I tried debugging the code and fHttpModule was not NULL.