UE4 显示帧率的几种姿势

在使用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);
	}
}
2.还可以自己实现上述功能,直接调用APlayerControllor的接口:
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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章