我正在循环一个http请求,并调用一个url来请求json指令。我必须循环,以便知道游戏应该做的下一件事。如果我把游戏打包,它会运行得很流畅。但在开发中并按下play时,游戏仍在继续,但除非我单击游戏窗口,否则视口上的输出大约是10fps。如果键盘或鼠标的焦点在另一个窗口而不是编辑器上,则视口面板似乎是故意这样做的。
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
}发布于 2020-01-24 00:37:57
当游戏未处于焦点状态时,您可以通过禁用该选项来禁用使用较少资源的编辑器:
Edit -> Editor Preferences -> General -> Performance -> Use Less CPU when in Background

https://stackoverflow.com/questions/59874170
复制相似问题