UE4显示帧率的几种姿势

发表于2018-02-08
评论0 1.58w浏览
在使用UE4 Editor或者UE4 Game时,有时候需要查看帧率,以及每帧耗时情况,本篇文章就给大家介绍几种显示帧率的方法。

一、在Editor中显示:

       1.键盘上 按下 ~

       2.可以看到有个输入框出现:
       3.在输入框输入 stat fps或者stat unit,出现帧率或者耗时:

二、也可以在偏好设置中设置:


设置后显示在:

还可以在视口中直接下拉选择显示与否:

三、在Game中显示(1):

       1.启动Game.exe后,键盘按下

       2.出现输入框,输入框中输入 stat fps或者stat unit,回车:

四、在Game中显示(2):

       1.在编辑器中,打开关卡蓝图编辑:

       2.右键添加节点:

       3.编辑Command:

       4.启动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

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引

0个评论