Search Unity

Accessing Rendering Statistics (FPS)

Discussion in 'Scripting' started by glenneroo, May 14, 2019.

  1. glenneroo

    glenneroo

    Joined:
    Oct 27, 2016
    Posts:
    231
    Does anyone know if it's possible to get the Graphics FPS/ms values as shown in the Rendering Statistics window? I have tried implementing at least 5 different variations of an FPS counter via Unity forums and other websites, including my own perversions, but none of them come close to the accuracy shown by the Rendering Statistics window.
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    This window trying to guess FPS in resulting build, without the editor overhead. I'm afraid it is too hard to replicate that. But you don't need it since in the editor you can check stats window and in the build theres no editor overhead, so 1/Time.deltaTime is your actual fps. If you want more informative counter, I suggest you check this tutorial https://catlikecoding.com/unity/tutorials/frames-per-second/
     
    wesleythomas360 and Joe-Censored like this.
  3. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,665
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    This ^^^

    1/Time.deltaTime should be your FPS for that frame. If you want you could do a little math to average it out over several frames to have a more stable counter.
     
  5. glenneroo

    glenneroo

    Joined:
    Oct 27, 2016
    Posts:
    231
    Thanks for the info everyone! I should have mentioned I'm already using the 1/deltaTime calculation, but it's always about half of what Unity stats shows. I also tried Graphy, it shows the same as 1/deltaTime, just in a pretty format.
     
  6. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    It's must be editor overhead. Check the profiler view.
     
  7. wesleythomas360

    wesleythomas360

    Joined:
    Feb 13, 2014
    Posts:
    2
    Thanks for clearing that up been spending pointless hrs to fig this out and getting confused. Should have just googled to come to this thread.

    My code for tracking updates and fps if anyone finds it useful :

    Code (CSharp):
    1. float updateCount = 0;
    2. float fixedUpdateCount = 0;
    3. float updateUpdateCountPerSecond = 0;
    4. float updateFixedUpdateCountPerSecond = 0;
    5. float FPS = 0;
    6. // Increase the number of calls to Update.
    7.         void Update()
    8.         {
    9.             if(isDebug)
    10.             updateCount += 1;
    11.         }
    12.  
    13.         // Increase the number of calls to FixedUpdate.
    14.         void FixedUpdate()
    15.         {
    16.             if(isDebug)
    17.             {
    18.                 fixedUpdateCount += 1;
    19.                 pointInstance = dynamicEventInfo.PointerDynamicInputEventUpdate();
    20.             }
    21.         }
    22.  
    23.         // Accumulate frames every second.
    24.         IEnumerator FPSTracker()
    25.         {
    26.             while (true)
    27.             {
    28.                 yield return new WaitForSeconds(1.0f);
    29.                 updateUpdateCountPerSecond = updateCount;
    30.                 updateFixedUpdateCountPerSecond = fixedUpdateCount;
    31.                 FPS = 1/Time.deltaTime;
    32.  
    33.                 updateCount = 0;
    34.                 fixedUpdateCount = 0;
    35.             }
    36.         }
     
    Last edited: Oct 25, 2020
    palex-nx likes this.