在使用UE4 Editor或者UE4 Game時,有時候需要查看幀率,以及每幀耗時情況。
在Editor中顯示:
- 鍵盤上 按下 ~
- 可以看到有個輸入框出現:
- 在輸入框輸入 stat fps或者stat unit,出現幀率或者耗時:
也可以在偏好設置中設置:
設置後顯示在:
還可以在視口中直接下拉選擇顯示與否:
在Game中顯示(1):
- 啓動Game.exe後,鍵盤按下 ~
- 出現輸入框,輸入框中輸入 stat fps或者stat unit,回車:
在Game中顯示(2):
- 在編輯器中,打開關卡藍圖編輯:
- 右鍵添加節點:
- 編輯Command:
- 啓動Game.exe,查看效果:
當然上面的方法是在Editor中實現,還可以直接在代碼中實現:
1.調用UKismetSystemLibrary::ExecuteConsoleCommand:
/**
* Executes a console command, optionally on a specific controller
*
* @param Command Command to send to the console
* @param SpecificPlayer If specified, the console command will be routed through the specified player
*/
UFUNCTION(BlueprintCallable, Category="Development",meta=(WorldContext="WorldContextObject"))
static void ExecuteConsoleCommand(UObject* WorldContextObject, const FString& Command, class APlayerController* SpecificPlayer = NULL );
其本質上是調用的APlayerControllor的接口:
void UKismetSystemLibrary::ExecuteConsoleCommand(UObject* WorldContextObject, const FString& Command, APlayerController* Player)
{
// First, try routing through the primary player
APlayerController* TargetPC = Player ? Player : UGameplayStatics::GetPlayerController(WorldContextObject, 0);
if( TargetPC )
{
TargetPC->ConsoleCommand(Command, true);
}
}
UGameEngine *GameEngine = GEngine ? Cast<UGameEngine>(GEngine) : nullptr;
UWorld* World = GameEngine ? GameEngine->GetGameWorld() : nullptr;
//ULevel *Level = World ? World->PersistentLevel : nullptr;
if (World)
{
APlayerController *Controller = World->GetFirstPlayerController();
if (Controller)
{
Controller->ConsoleCommand(FString(command), false);
}
}
本文地址:http://blog.csdn.net/u011417605/article/details/77247658
交流qq:1245178753