Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity mobile device 30fps locked

Tags:

c#

unity3d

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:

https://i.gyazo.com/33a4f6d2f87899568472b1f890bca1ec.png

What should I do to unlock it from 30fps?

like image 434
J.K. Harthoorn Avatar asked Oct 31 '17 08:10

J.K. Harthoorn


People also ask

Why is my game locked at 30 FPS?

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.

How do I play games at 60fps on Android?

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.


1 Answers

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.

like image 172
vmchar Avatar answered Oct 29 '22 21:10

vmchar