【问题标题】:UE4 http request loopUE4 http请求循环
【发布时间】:2020-05-09 11:11:15
【问题描述】:

我正在循环一个 http 请求并调用一个请求 json 指令的 url。 我必须循环才能知道游戏接下来应该做的事情。如果我打包游戏,它工作顺利。但在开发和按下播放时,游戏确实继续,但视口上的输出就像 10 fps,除非我单击游戏窗口。如果您的键盘或鼠标聚焦在另一个窗口而不是编辑器上,则视口面板似乎是故意这样做的。

Request = FHttpModule::Get().CreateRequest(); 

Request->OnProcessRequestComplete().BindUObject(this, &ABoxGridActor::OnResponseReceived);
//   //This is the url on which to process the request
Request->SetURL("http://localhost:8092"); 
Request->SetVerb("GET");
Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));
//Request->ProcessRequest();

////not timer loop, one time only
GetWorldTimerManager().SetTimer(tmr, this, &ABoxGridActor::RepeatingFunction, 0.2f, true);

void ABoxGridActor::RepeatingFunction()
{
    if (!boolHasPassed)
    {
        boolHasPassed = true;
        Request->ProcessRequest();
        return;
    }

}

void ABoxGridActor::OnResponseReceived(FHttpRequestPtr RequestP, FHttpResponsePtr Response, bool bWasSuccessful)
{
    boolHasPassed = false;

    //codes
}

【问题讨论】:

  • 焦点问题或低 fps 与您的 http 循环有何关系?

标签: unreal-engine4


【解决方案1】:

当游戏不在焦点时,您可以通过禁用选项来使用更少的资源来禁用编辑器:

Edit -> Editor Preferences -> General -> Performance -> Use Less CPU when in Background

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-16
    • 1970-01-01
    • 2014-02-14
    • 1970-01-01
    • 2013-04-10
    相关资源
    最近更新 更多