Since yesterday, my unity game is locked 30fps on an android device. Before it was like 150fps.. I disabled v-sync. This is the only script I added yesterday:
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();
}
}
}
I don't this can be the problem. I added this to the GameManager:
void Awake()
{
Application.targetFrameRate = -1;
QualitySettings.vSyncCount = 0;
}
The profiler shows this:
What should I do to unlock it from 30fps?
If you experience FPS capped to 30/60 or if your framerate is unstable, it is most likely related to your VSync settings. Enabling VSync will force the game to run maximum at your monitors refresh rate (usually 60 Hz) and will in turn will eliminate tearing.
Launch the Settings app on your phone and tap Display. Select Advanced on the resulting screen. Tap Refresh rate. Select the highest possible refresh rate from the options on your screen.
By default, Unity locks fps for specific values, according to the current platform. Documentation says that the default for Android is 30, which is used by most Android devices. Also it says:
The default targetFrameRate is a special value -1, which indicates that the game should render at the platform's default frame rate.
Which is 30 for mobile as it's said in the article.
Also, you can have as much fps as possible while running your game in editor, it maybe 150 or more, but it's really bad practice to have more than 60 (max value for iPhones and some Androids). If you have more than 60 fps you can't actually see the difference because device's display can't actually render more than 60 frames per second, but it takes battery and CPU resources and all those calculations (for extra 60+ fps) are useless and even bad.
To make your fps more than 30, you can set it for 60 as you are doing in your code:
Application.targetFrameRate = 60;
Also v-sync is mostly don't work on mobile, so you don't need to bother with this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With