Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

FPS Display script

Discussion in 'iOS and tvOS' started by sigsom, Dec 31, 2009.

  1. sigsom

    sigsom

    Joined:
    Aug 9, 2009
    Posts:
    133
    Would this script accurately display an in-game FPS rate? Currently I get 30 on my 3GS
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class FPSDisplayScript : MonoBehaviour {
    5.     float timeA;
    6.     public int fps;
    7.     public int lastFPS;
    8.     public GUIStyle textStyle;
    9.     // Use this for initialization
    10.     void Start () {
    11.         timeA = Time.timeSinceLevelLoad;
    12.         DontDestroyOnLoad (this);
    13.     }
    14.    
    15.     // Update is called once per frame
    16.     void Update () {
    17.         //Debug.Log(Time.timeSinceLevelLoad+" "+timeA);
    18.         if(Time.timeSinceLevelLoad  - timeA <= 1)
    19.         {
    20.             fps++;
    21.         }
    22.         else
    23.         {
    24.             lastFPS = fps + 1;
    25.             timeA = Time.timeSinceLevelLoad;
    26.             fps = 0;
    27.         }
    28.     }
    29.     void OnGUI()
    30.     {
    31.         GUI.Label(new Rect( 450,5, 30,30),""+lastFPS,textStyle);
    32.     }
    33. }
    34.  
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,145
  3. sigsom

    sigsom

    Joined:
    Aug 9, 2009
    Posts:
    133
    Hey thanks for that, im getting roughly the same numbers but the one I made gets updated less frequently. Which I guess is better performance wise but not testing wise.

    However no matter which fps meter I use I cannot get my scenes over 30 FPS. Even my menu runs at 30 FPS. Is there a hardcap somewhere I'm not seeing? I have my fixed timestep set to 0.05, physics influences set to 1, and I turned on interpolation on rigidobjects. Still no dice.

    Also is my main scene too much for anything other than 3gs? I currently have stats of 27 drawcalls, 29.1k tris, 13.5k verts, 10 textures @ 1.8mb. It runs great on my iphone even with AA on at the beautiful setting, but my artist said it runs like crap on his 3G. He was using a really old software version though.
     
  4. Dark-Table

    Dark-Table

    Joined:
    Nov 25, 2008
    Posts:
    260
    in AppController.mm you can modify this line to change the frame rate cap:
    Code (csharp):
    1. #define kFPS    30.0
    Your scene sounds way too heavy to run at a higher frame rate though.
     
  5. bpatters

    bpatters

    Joined:
    Oct 5, 2009
    Posts:
    164
    You need to stay under 10k vertices and 20 drawcalls for your game to have a chance of performing well on a 3G. I have a 3G as my primary test device and that's what I've seen.

    The primary weakness of the 3G is its CPU is really slow so you won't be able to have much physics, AI, or any other CPU related activities going on.
     
  6. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Another option for a frame rate meter is FPS Graph.



    It also breaks down the CPU and Rendering computation, which can be helpful in debugging whether the GPU or CPU is your bottle-neck.
     
  7. Victor-K

    Victor-K

    Joined:
    Nov 10, 2013
    Posts:
    208
    Smart FPS Meter allows you to quickly and easily getting and display performance info, frames per second and milliseconds data, usage memory and hardware info.