うにてぃブログ

主にUnityとC#に関する記事を書いていきます

【Unity】FPS を固定する

Unity は初期状態で FPSEvery V Blank に設定されており、プラットフォームのデフォルトFPSになってしまいます

そのため、固定する場合には Application.targetFrameRate に指定した FPS を設定する必要があります

またドキュメントにも記載してあるように QualitySettings.vSyncCount が 0じゃない場合 Application.targetFrameRate の指定は無視されてしまうため、忘れずに0を指定するか Quality の設定から Dont Sync` に設定する必要があります ※デフォルトだと1 (Every V Blank)

Additionally if the QualitySettings.vSyncCount property is set, the targetFrameRate will be ignored and instead the game will use the vSyncCount and the platform's default render rate to determine the target frame rate. For example, if the platform's default render rate is 60 frames per second and vSyncCount is set to 2, the game will target 30 frames per second.

// 60FPS を指定する場合
private void Awake()
{
    // Vsync Count を 0にすることにより、FPS を固定できるようになる
    QualitySettings.vSyncCount = 0;
    Application.targetFrameRate = 60;
}