【问题标题】:How Unreal Engine 4 polls/handle input, in terms of input timing?虚幻引擎 4 如何根据输入时序轮询/处理输入?
【发布时间】:2020-04-28 06:12:32
【问题描述】:

某些类型的游戏需要超过 0.0166...秒的精度,包括节奏动作游戏。在这种情况下,基于帧的输入处理对于玩家来说可能是不够的。

我在 Unity 方面有点经验,我知道在最近的版本之前,unity 会处理每帧的输入(更新调用)。这意味着来自播放器的输入与显示的刷新率一起被轮询,通常为每秒 60 帧。

现在我是 UE4 的新手,想知道它如何处理来自玩家的输入。我看到 Tick 或 Tickcomponent 的行为似乎与统一的 Update 相似。 (UE4 文档说“在此 ActorComponent 上的每一帧都调用一个函数)UE4 是否也处理每帧的输入,或者即使渲染帧会比实际输入时间晚一点,时间戳也可用于输入?

一个场景:输入具体发生在 4.052 秒,任何基于帧的调用都发生在 4.057 秒。

在这种情况下,UE4 是否认为输入发生在 4.052 或 4.057?

【问题讨论】:

    标签: input unreal-engine4


    【解决方案1】:

    它是基于帧的,而不是时间戳。 你可以自己检查。 创建一个新的 C++ 类 > 字符。 在该类的 Visual Studio 中找到 Tick() 并像这样更改它:

    void NameOfClass::Tick(float DeltaTime)
        Super::Tick(DeltaTime);
        if (GetWorld() != nullptr)
        {
            UE_LOG(LogTemp, Warning, TEXT("DeltaTime of Frame: %f"), GetWorld()->TimeSeconds)// Returns time in seconds since world was brought up for play, IS stopped when game pauses, IS dilated/clamped
            UE_LOG(LogTemp, Warning, TEXT("DeltaTime of Frame FDateTime ms: %f"), FDateTime::Now().GetMillisecond())// Gets the local date and time on this computer.
        }
    

    然后找到其中一个输入函数,例如Jump() 并像这样改变它:

    void NameOfClass::Jump()
    {
        Super::Jump();
        if (GetWorld() != nullptr)
        {
            UE_LOG(LogTemp, Warning, TEXT("DeltaTime of Jump: %f"), GetWorld()->TimeSeconds)// Returns time in seconds since world was brought up for play, IS stopped when game pauses, IS dilated/clamped
            UE_LOG(LogTemp, Warning, TEXT("DeltaTime of Jump FDateTime ms: %f"), FDateTime::Now().GetMillisecond())// Gets the local date and time on this computer.
        }
    }
    

    不要忘记 .cpp 顶部的 UWorld 的#include

    #include "Runtime/Engine/Classes/Engine/World.h"
    

    编译。 在 UE4Editor 中将类拖放到您的关卡中,点击播放,您将看到每一帧的 DeltaTime 正在发生。如果您按空格键(默认调用 Jump())并立即 ESC 停止游戏,您可以比较 2 个 DeltaTimes。完全相同的! 我希望这能回答你的问题。

    【讨论】:

      猜你喜欢
      • 2015-10-12
      • 2021-07-09
      • 1970-01-01
      • 2017-10-31
      • 2020-03-24
      • 2020-09-11
      • 1970-01-01
      • 2020-07-24
      • 2015-02-04
      相关资源
      最近更新 更多