【问题标题】:Unity mobile device 30fps lockedUnity 移动设备 30fps 锁定
【发布时间】:2020-05-22 02:25:29
【问题描述】:

从昨天开始,我的 Unity 游戏在 Android 设备上被锁定为 30fps。在它像 150fps 之前……我禁用了垂直同步。这是我昨天添加的唯一脚本:

public static class SaveLoadProgress {

public static void Save()
{
    LevelManager levelManager = GameObject.Find ("GameManager").GetComponent<LevelManager> ();
    BinaryFormatter bf = new BinaryFormatter();
    FileStream file = File.Create (Application.persistentDataPath + "/savedProgress.1912");
    bf.Serialize(file, levelManager.levelReached);
    file.Close();
}

public static void Load() 
{
    LevelManager levelManager = GameObject.Find ("GameManager").GetComponent<LevelManager> ();
    if(File.Exists(Application.persistentDataPath + "/savedProgress.1912")) 
    {
        BinaryFormatter bf = new BinaryFormatter();
        FileStream file = File.Open(Application.persistentDataPath + "/savedProgress.1912", FileMode.Open);
        levelManager.levelReached = (int)bf.Deserialize(file);
        file.Close();
    }
}
}

我不认为这可能是问题所在。 我将此添加到 GameManager:

    void Awake()
{
    Application.targetFrameRate = -1;
    QualitySettings.vSyncCount = 0;
}

分析器显示:

我应该怎么做才能从 30fps 解锁?

【问题讨论】:

  • 好问题。恭喜。

标签: c# unity3d


【解决方案1】:

默认情况下,Unity 根据当前平台锁定特定值的 fps。 Documentation 表示 Android 的默认值为 30,大多数 Android 设备都使用该值。它还说:

默认的targetFrameRate是一个特殊的值-1,表示游戏应该以平台的默认帧率渲染。

如文章中所述,移动设备为 30。

此外,在编辑器中运行游戏时,您可以拥有尽可能高的 fps,它可能是 150 或更多,但超过 60(iPhone 和某些 Android 设备的最大值)确实是一种糟糕的做法。如果超过 60 fps,您实际上看不到差异,因为设备的显示器实际上不能每秒渲染超过 60 帧,但它需要电池和 CPU 资源,所有这些计算(额外的 60+ fps)都是无用的甚至不好。

要使您的 fps 超过 30,您可以将其设置为 60,就像您在代码中所做的那样:

Application.targetFrameRate = 60;

此外,垂直同步在移动设备上大多不起作用,因此您无需为此烦恼。

【讨论】:

  • 谢谢,我以为我已经这样做了,但现在可以了。奇怪的是,几天前 fps 在移动设备上也只有 150
【解决方案2】:

不是答案,而是对@vmchar 答案的更多扩展评论:

我不同意 VSync 不能在移动设备上运行。我们将Application.targetFrameRate 设置为 60,但是,我们仍然遇到 CPU 破坏 GPU 的问题。设置 VSync 会强制它等待。帧率从 https://imgur.com/a/lE0LedF 变为 https://imgur.com/a/EPq6q7T

Unity 不建议同时使用两者:

Application.targetFrameRate 是一种“软”vsync,可用于限制没有设置硬件 vsync 的模拟速率(例如在服务器上)。不希望在设置了 vSyncCount 的情况下使用 targegFrameRate,因为 CPU 帧可能会漂移并导致渲染命令稍后安排并错过下一个 vsync。

但编辑器中不支持 VSync 设置,因此您仍然可能会遇到问题。

全线程:https://forum.unity.com/threads/gfx-presentframe-taking-4x-as-long-but-only-for-intermittent-periods.538254

【讨论】:

    【解决方案3】:

    如其他答案所述,如果 Unity 将您的帧速率锁定为 30 或其他值。我的锁定在 30 FPS,只需在您的 Start() 方法中添加 Application.targetFrameRate = 60;,或者在您想在应用程序生命周期中设置帧率时。

    void Start()
    {
        Application.targetFrameRate = 60;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多