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);
		}
	}

本文地址: UE4 显示帧率的几种姿势_GreenArrowMan-CSDN博客-CSDN博客
交流qq:1245178753

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GreenArrowMan

请打钱~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值