- Application.targetFrameRate
- Success!
- Submission failed
- Description
- Application.targetFrameRate
- Success!
- Submission failed
- Description
- Мобильное устройство Unity 30fps заблокировано
- 3 ответа
- Application.targetFrameRate
- Success!
- Submission failed
- Description
- Application.targetFrameRate
- Success!
- Submission failed
- Description
Application.targetFrameRate
Success!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Submission failed
For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Description
Specifies the frame rate at which Unity tries to render your game.
The default value of Application.targetFrameRate is -1. In the default case, Unity uses the platform’s default target frame rate.
Otherwise, targetFrameRate is a positive integer representing frames per second (fps). Unity tries to render your game at that frame rate.
Use targetFrameRate to control the frame rate of your game. For example, you might need to reduce your game’s frame rate to make sure your game displays smoothly and consistently. You can also reduce your game’s frame rate to conserve battery life on mobile devices and avoid overheating.
Note that platform and device capabilities affect the frame rate at runtime, so your game might not achieve the target frame rate.
targetFrameRate and vSyncCount
Both Application.targetFrameRate and QualitySettings.vSyncCount let you control your game’s frame rate for smoother performance. targetFrameRate controls the frame rate by specifying the number of frames your game tries to render per second, whereas vSyncCount specifies the number of screen refreshes to allow between frames.
Mobile platforms ignore QualitySettings.vSyncCount. Use Application.targetFrameRate to control the frame rate on mobile platforms.
VR platforms ignore both QualitySettings.vSyncCount and Application.targetFrameRate. Instead, the VR SDK controls the frame rate.
On all other platforms, Unity ignores the value of targetFrameRate if you set vSyncCount . When you use vSyncCount , Unity calculates the target frame rate by dividing the platform’s default target frame rate by the value of vSyncCount . For example, if the platform’s default render rate is 60 fps and vSyncCount is 2, Unity tries to render the game at 30 frames per second.
Platform notes
Standalone platforms
On standalone platforms, the default frame rate is the maximum achievable frame rate. To use the platform’s default frame rate, set Application.targetFrameRate to -1.
Mobile platforms
A mobile device’s maximum achievable frame rate is the refresh rate of the screen. For example, a device with a refresh rate of 60 Hertz has a maximum achievable frame rate of 60 frames per second. To target the maximum achievable frame rate, set Application.targetFrameRate to the screen’s refresh rate. Screen.currentResolution contains the screen’s refresh rate.
To conserve battery power, the default frame rate on mobile platforms is lower than the maximum achievable frame rate. Usually, the default frame rate on mobile platforms is 30 fps. To target the default frame rate, set Application.targetFrameRate to -1.
To target a frame rate other than the maximum achievable frame rate or the platform default on mobile platforms, set Application.targetFrameRate to the screen’s refresh rate divided by an integer. If the target frame rate is not a divisor of the screen refresh rate, the resulting frame rate is always lower than Application.targetFrameRate.
Note that mobile platforms ignore the QualitySettings.vSyncCount setting. Instead, you use the target frame rate to achieve the same effect as setting the vertical sync count. To do this, divide the screen’s refresh rate by the number of vertical syncs you want to allow between frames, and set Application.targetFrameRate to this number.
For example, on a device with a screen refresh rate of 60 Hz, to allow:
- 1 vertical sync between frames, set targetFrameRate to 60.
- 2 vertical syncs between frames, set targetFrameRate to 30.
- 3 vertical syncs between frames, set targetFrameRate to 20.
WebGL
By default, WebGL lets the browser choose a frame rate that matches its render loop timing. To use the browser’s chosen frame rate, set Application.targetFrameRate to -1.
Usually, the browser’s chosen frame rate gives the smoothest performance. You should only set a different target frame rate on WebGL if you want to throttle CPU usage.
VR
VR platforms ignore Application.targetFrameRate and QualitySettings.vSyncCount. Instead, the VR SDK controls the frame rate.
Unity Editor
In the Editor, Application.targetFrameRate affects only the Game View. It has no effect on other Editor windows.
Is something described here not working as you expect it to? It might be a Known Issue. Please check with the Issue Tracker at issuetracker.unity3d.com.
Copyright ©2021 Unity Technologies. Publication Date: 2021-10-08.
Источник
Application.targetFrameRate
Success!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Submission failed
For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Description
Instructs the game to try to render at a specified frame rate.
The default targetFrameRate is a special value of -1, which indicates that the game should render at the platform’s default frame rate. This default rate depends on the platform:
— On standalone platforms the default frame rate is the maximum achievable frame rate.
— On mobile platforms the default frame rate is less than the maximum achievable frame rate due to the need to conserve battery power. Typically on mobile platforms the default frame rate is 30 frames per second.
— All mobile platforms have a fix cap for their maximum achievable frame rate, that is equal to the refresh rate of the screen (60 Hz = 60 fps, 40 Hz = 40 fps, . ). Screen.currentResolution contains the screen’s refresh rate.
— Additionally, all mobile platforms can only display frames on a VBlank. Therefore, you should set the targetFrameRate to either -1, or a value equal to the screen’s refresh rate, or the refresh rate divided by an integer. Otherwise, the resulting frame rate is always lower than targetFrameRate . Note: If you set the targetFrameRate to the refresh rate divided by an integer, the integer division leads to the same effective fps as setting QualitySettings.vSyncCount to the same value as that integer.
— iOS ignores the QualitySettings.vSyncCount setting. Instead, the device displays frames on the first possible VBlank after the frame is ready and your application achieves the targetFrameRate .
— On WebGL the default value lets the browser choose the frame rate to match its render loop timing which generally produces the smoothest results. Non-default values are only recommended if you want to throttle CPU usage on WebGL.
— When using VR Unity will use the target frame rate specified by the SDK and ignores values specified by the game.
Setting targetFrameRate does not guarantee that frame rate will be achieved. There can be fluctuations due to platform specifics, or the game might not achieve the frame rate because the device is too slow.
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.
In the Editor, targetFrameRate affects only the Game View. It has no effect on other Editor windows.
Is something described here not working as you expect it to? It might be a Known Issue. Please check with the Issue Tracker at issuetracker.unity3d.com.
Copyright ©2021 Unity Technologies. Publication Date: 2021-10-08.
Источник
Мобильное устройство Unity 30fps заблокировано
Со вчерашнего дня моя игра в единство заблокирована 30fps на устройстве Android. До этого было 150 кадров в секунду. Я отключил v-sync. Это единственный скрипт, который я добавил вчера:
Я не могу быть проблемой. Я добавил это в GameManager:
Профилировщик показывает это:
Что я должен сделать, чтобы разблокировать его с 30fps?
3 ответа
По умолчанию Unity блокирует fps для определенных значений в соответствии с текущей платформой. Документация говорит, что по умолчанию для Android установлено значение 30, которое используется большинством Android устройства . Также это говорит:
По умолчанию targetFrameRate имеет специальное значение -1, которое указывает, что игра должна отображаться с частотой кадров платформы по умолчанию.
Это 30 для мобильных устройств, как сказано в статье.
Кроме того, вы можете иметь как можно больше fps при запуске игры в редакторе, может быть, 150 или больше, но очень плохо иметь более 60 (максимальное значение для iPhone и некоторых Android). Если у вас более 60 кадров в секунду, вы не сможете увидеть разницу, потому что дисплей устройства не может отображать более 60 кадров в секунду, но он потребляет ресурсы батареи и процессора, и все эти вычисления (для дополнительных 60 + кадров в секунду) бесполезны и даже плохо.
Чтобы ваш fps был больше 30, вы можете установить его на 60, как вы делаете в своем коде:
Кроме того, V-Sync в основном не работает на мобильных устройствах, поэтому вам не нужно беспокоиться об этом.
Не ответ, а скорее расширенный комментарий к ответу @ vmchar:
Я не согласен, что VSync не работает на мобильном телефоне. У нас Application.targetFrameRate установлено значение 60, однако у нас все еще была проблема с загрузкой процессора в графический процессор. Установка VSync заставляет его ждать. Частота смены кадров изменилась с https://imgur.com/a/lE0LedF на https://imgur.com/a/EPq6q7T.
Unity не рекомендует использовать оба сразу:
Application.targetFrameRate является «мягкой» vsync и полезна для ограничения скорости симуляции без установки аппаратного vsync (например, на серверах). Не желательно использовать targetgFrameRate с установленным vSyncCount, так как кадр ЦП может сместиться и привести к тому, что команды рендеринга будут запланированы позже и пропустят следующий vsync.
Настройки VSync в редакторе не соблюдаются, поэтому у вас все равно могут возникнуть проблемы.
Источник
Application.targetFrameRate
Success!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Submission failed
For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Description
Instructs game to try to render at a specified frame rate.
The default targetFrameRate is a special value -1, which indicates that the game should render at the platform’s default frame rate. This default rate depends on the platform:
— On standalone platforms the default frame rate is maximum achievable frame rate.
— On mobile platforms the default frame rate is less than the maximum achievable frame rate due to need to conserve battery power. Typically on mobile platforms the default frame rate is 30 frames per second.
— On WebGL the default value lets the browser choose the frame rate to match its render loop timing which generally produces the smoothest results. Non-default values are only recommended if you want to throttle CPU usage on WebGL.
— When using VR Unity will use the target frame rate specified by the SDK and ignore values specified by the game.
Setting targetFrameRate does not guarantee that frame rate will be achieved. There can be fluctuations due to platform specifics, or the game might not achieve the frame rate because the computer is too slow.
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.
In the editor, targetFrameRate affects only the Game window. It has no effect on other editor windows.
Did you find this page useful? Please give it a rating:
Источник
Application.targetFrameRate
Success!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Submission failed
For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Description
Instructs the game to try to render at a specified frame rate.
The default targetFrameRate is a special value of -1, which indicates that the game should render at the platform’s default frame rate. This default rate depends on the platform:
— On standalone platforms the default frame rate is the maximum achievable frame rate.
— On mobile platforms the default frame rate is less than the maximum achievable frame rate due to the need to conserve battery power. Typically on mobile platforms the default frame rate is 30 frames per second.
— All mobile platforms have a fix cap for their maximum achievable frame rate, that is equal to the refresh rate of the screen (60 Hz = 60 fps, 40 Hz = 40 fps, . ). Screen.currentResolution contains the screen’s refresh rate.
— Additionally, all mobile platforms can only display frames on a VBlank. Therefore, you should set the targetFrameRate to either -1, or a value equal to the screen’s refresh rate, or the refresh rate divided by an integer. Otherwise, the resulting frame rate is always lower than targetFrameRate . Note: If you set the targetFrameRate to the refresh rate divided by an integer, the integer division leads to the same effective fps as setting QualitySettings.vSyncCount to the same value as that integer.
— iOS ignores the QualitySettings.vSyncCount setting. Instead, the device displays frames on the first possible VBlank after the frame is ready and your application achieves the targetFrameRate .
— On WebGL the default value lets the browser choose the frame rate to match its render loop timing which generally produces the smoothest results. Non-default values are only recommended if you want to throttle CPU usage on WebGL.
— When using VR Unity will use the target frame rate specified by the SDK and ignores values specified by the game.
Setting targetFrameRate does not guarantee that frame rate will be achieved. There can be fluctuations due to platform specifics, or the game might not achieve the frame rate because the device is too slow.
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.
In the Editor, targetFrameRate affects only the Game View. It has no effect on other Editor windows.
Did you find this page useful? Please give it a rating:
Источник