Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Application.Targetframerate

Discussion in 'Android' started by unity2, Jul 29, 2019.

  1. unity2

    unity2

    Joined:
    Jan 10, 2013
    Posts:
    23
    Hi,

    Working on optimisation of my android project. My target frame rate was initially 30 and was getting 24-25 fps normally and fps drops to 15 occasionally. Just for testing, I changed my target frame rate to 60. Now my normal fps is around 50 and occasionally getting drops to 25 fps. I didn't get the functionality of target frame rate. According to the docs, it should give the lowest frame rate if it's less than the target. How can my normal fps be 50 if earlier it never reached 30?
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    How are you measuring FPS?
     
  3. unity2

    unity2

    Joined:
    Jan 10, 2013
    Posts:
    23
    Here's the code to measure fps
    Code (CSharp):
    1.    
    2.     private float updateInterval = 1.0f;
    3.     private float frames = 0;
    4.     private double lastInterval;
    5.     public  float fps;
    6.  
    7.  
    8. void Start ()
    9.     {
    10.  
    11.         lastInterval = Time.realtimeSinceStartup;
    12.         frames = 0;
    13.  
    14.     }
    15. public  void Update ()
    16.     {
    17.         ++frames;
    18.  
    19.         float timeNow = Time.realtimeSinceStartup;
    20.  
    21.         if (timeNow > lastInterval + updateInterval) {
    22.             fps = frames / (timeNow - (float)lastInterval);
    23.             frames = 0;
    24.             lastInterval = timeNow;
    25.  
    26.         }
    27.     }