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

Framerate drops when screen is touched

Discussion in 'iOS and tvOS' started by Brady, Oct 30, 2008.

  1. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    According to a couple of different tests I've done, it appears that, even without any code to process the input, the framerate will drop from 30fps to 15fps simply by touching and holding the screen. As long as you touch the screen, the fps will remain at about 15fps, and then, provided your scene and logic are simple enough, as soon as you release, the fps will shoot right back up to 30fps.

    This can be tested by using a barebones scene to ensure the high "idle" framerate. Then just touch and hold the screen and you'll see it drop in half.

    Is there any way around this? It is causing the input on my game to feel REALLY sluggish and unresponsive.
     
  2. phoen

    phoen

    Joined:
    Oct 25, 2005
    Posts:
    94
    i also noticed this, in my game as soon as i touch the screen the fps never go over 15.
    but in the gamemenu, which has no meshes (only the ondrawgui function) the framerate doesnt drop.
     
  3. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    Same here ... I noticed when the finger is on the screen.. and then I start moving around the iphone a little, it gets really sluggish.
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Do you have a lot of OnGUI calls?
    Try reducing the amount of OnGUI calls. Even if you don't do a lot in them, they can be expensive. OnGUI calls increase the more input events are coming in.
    MonoBehaviour.useGUILayout = false; can greatly improve performance if you are not using GUI layout in your gui.

    If not, make a small sample application and report a bug.
     
  5. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    The only GUI element I have is my fps drawer - the standard one. I did remove it, and though I can't know for sure since my fps drawer is now gone, it does seem to run smoother, so I think that "fixed" it.

    But that's pretty odd. There's got to be a way to display simple textual content on-screen without halving the framerate.
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
     
  7. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    UPDATE: I wasn't using GUI layouts, but I went ahead and tried using useGUILayout = false as you suggested, and it seems to have solved the problem. I didn't know that was enabled by default, but now I'll remember to disable it in all my GUI elements when using iPhone.

    Quick question on this though: the docs are rather ambiguous about this particular setting - I gathered that it should be set in an object with a GUI component, but I wasn't sure where the best place was to call it. Is it something that needs to be set each frame, or can it be set in Awake() or Start()? And does it have to be set on each object with a GUI component, or does it only need to be set somewhere once in the entire scene?
     
  8. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Awake is enough
     
  9. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Is this going to be rolled into Unity 2.x proper? It seems like a great optimisation feature to have in general :)
     
  10. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    sounds good, but how do I use this correctly? writing MonoBehaviour.useGUILayout = false; gives an error and if I do this.useGUILayout = false; there's no error, but I also can't see any improvement... if I touch the screen the framerate still goes from 30 to 15...
     
  11. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    col000r... it wont solve the problem if you still have a heap of OnGUI stuff to display. It's a matter of totally reducing your OnGUI content AND not using GUILayout AND using the useGUILayout = false;

    I hated the days of using GUITextures to build interfaces, and now it seems we are destined to go back to it to get good performance on the iPhone.

    At least we wont have to worry about scaling issues and for different resolutions, but it does make it hard to add a static non/scalable interface and have stuff like camera zoom etc... unless we go to the old way of using a separate camera for GUITextures.... but then the extra overhead again on the iPhone by having it render 2 cameras.

    I guess its going to come down to lots of testing to see what's going to perform better....
     
  12. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    do I place useGUILayout in every script or just one? I don't really understand how and where to put this.
     
  13. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Put it in the Awake() function of every script that has an OnGUI() function.
     
  14. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    Thanks Seon, but I don't have any OnGUI functions in any of my scripts... but I'm still getting the same framerate issues on press, which is strange.
     
  15. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    I think if you have any GUI objects (like GUIText), then you need to put this.useGUILayout = false in Awake() according to what Joachim said.

    this.useGUILayout - false worked for me in the javascript FPSCounter that I have, and it eliminated the framerate drop. If that's not working, you may be calling it on a object that doesn't have a GUI component, perhaps? Some clarification on this would probably be good, but for now I think that'll get you going.
     
  16. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    I get this error:
    Code (csharp):
    1.  
    2. Assets/_Scripts/Mode Manager.js(10,23): BCE0020: An instance of type 'UnityEngine.MonoBehaviour' is required to access non static member 'useGUILayout'.
    3.  
    as said above, how do i use it?
     
  17. Bael

    Bael

    Joined:
    Jul 21, 2008
    Posts:
    106
    I was getting a similar slowdown, but it was being caused by polling touch data in Update(). Moving my touch checking / handling into FixedUpdate() mostly resolved the issue. It still goes down, but the change is more like 30->26 rather than 30->15.
     
  18. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    What I'm doing is: "this.useGUILayout = false;"

    That should work. And according to Joachim, just put it in your Awake() for that object.

    I do think this needs to be explained more in the docs though. I'm sure that's on their To Do list.

    Oh, and putting it in your FixedUpdate() may not be the best idea in a lot of cases, particularly if you have physics in your game but have set the time step really low for performance reasons. That'll mean that FixedUpdate isn't called very frequently, which means even though your rendering fps will remain high, your user may experience frustration with input because it takes several noticeable milliseconds to respond to input.
     
  19. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    That fixed all my lag problems! Nice!
     
  20. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    useGUILayout only does something when you have a OnGUI call on the same script.
     
  21. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    I'm sure I'm missing something obvious, but I can't find a useGUILayout property in my C# script. The code is:

    Code (csharp):
    1.  
    2. public class RollerGUI : MonoBehaviour {
    3.     public bool displayResults = true;
    4.    
    5.     void Awake()
    6.     {
    7.         Debug.Log("WOKE UP!");
    8.         this.useGUILayout = false;
    9.     }
    10.  
    11. [...]
    12.  
    And the error:


    `RollerGUI' does not contain a definition for `useGUILayout'

    I couldn't find a reference on useGUILayout on the MonoBehaviour documentation.

    Can anyone point me to what I'm obviously missing so I can smack my forehead?
     
  22. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    I think it should work if you attach that script to a GameObject that has a GUI component such as GUIText or 3D Text. If you're only using the Unity GUI script calls, I'm not sure in that case...
     
  23. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Hmm, the script itself is the one doing the GUI calls on its OnGUI method. It is attached to an in-game object, but I get the error on saving (when it's compiled).
     
  24. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    Ahh, so in that case you are using UnityGUI calls. In that case, that's a really good question. I hope someone here can answer it quickly. Thus far, I've only used it on GameObjects with GUI components added and it works fine. But I can see now why you're running into that problem.
     
  25. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Use useGUILayout is not related to 1.x style GUI components. It is a property on the monobehaviour which you should setup in MonoBehaviour.
    Obviously this property can't be found in the online docs but only in the iPhone specific docs on your machine. Also if you get a compiler error using useGUILayout = false; Are you sure you are running Unity iPhone at all?
     
  26. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Hi Joachim,

    Thanks for the clarification. I am running Unity 2.0, using scripts descended from MonoBehaviour, but was unaware that this property was specific to the iPhone version. Thanks for the clarification.
     
  27. billyzelsnack

    billyzelsnack

    Joined:
    Dec 31, 2008
    Posts:
    92
    I'm also having crushing framerate issue when the iphone is touched. From around 29 down to 15 or so.

    I have a single script running in my game and I have the this.GUILayout=false in its Awake. Here's the profiles with and without touching..

    ---- WITHOUT TOUCHING -------
    iPhone Unity internal profiler stats:
    cpu-player> min: 15.7 max: 21.8 avg: 18.4
    cpu-ogles-drv> min: 5.0 max: 9.1 avg: 6.7
    cpu-present> min: 1.2 max: 4.6 avg: 1.4
    frametime> min: 30.0 max: 36.2 avg: 33.3
    draw-call #> min: 17 max: 17 avg: 17
    tris #> min: 2816 max: 2816 avg: 2816
    verts #> min: 1439 max: 1439 avg: 1439
    player-detail> physx: 1.7 animation: 3.6 skinning: 0.0 render: 11.9 fixed-update-count: 1 .. 2
    mono-scripts> update: 0.4 fixedUpdate: 0.4 coroutines: 0.0
    mono-memory> used heap: 2240512 allocated heap: 2740224

    ---- WITH TOUCHING -------
    iPhone Unity internal profiler stats:
    cpu-player> min: 22.5 max: 31.5 avg: 27.5
    cpu-ogles-drv> min: 3.6 max: 10.6 avg: 5.4
    cpu-present> min: 1.3 max: 4.2 avg: 1.9
    frametime> min: 33.9 max: 69.5 avg: 64.4
    draw-call #> min: 17 max: 17 avg: 17
    tris #> min: 2816 max: 2816 avg: 2816
    verts #> min: 1439 max: 1439 avg: 1439
    player-detail> physx: 4.7 animation: 7.1 skinning: 0.0 render: 11.5 fixed-update-count: 2 .. 4
    mono-scripts> update: 0.6 fixedUpdate: 0.6 coroutines: 0.2
    mono-memory> used heap: 2338816 allocated heap: 2740224


    The cpu-player jumps up dramatically. Strangely physx jumps up dramatically as well. This is strange because for these profiles I immediately return out of Update / FixedUpdate and my single physics sphere is just sleeping.
     
  28. jojan

    jojan

    Joined:
    Nov 6, 2008
    Posts:
    63
    I'm seeing major performance problems similar to billyzelsnak's. I tried the useGUILayout trick, and also tried deleting the only GUI object in my scene, with no luck.

    I'm getting a steady 33.3 average frametime in my test scene. When I touch the screen and move my finger constantly, it rises to about 36 average. This is without any GUI objects whatsoever, and without referencing iPhoneInput at all.

    If I introduce my framerate counter (with useGUILayout = false), the frametime goes up to about 45 average.

    This is a critical problem for my project. Any word on when this will be improved?
     
  29. chips

    chips

    Joined:
    Nov 30, 2007
    Posts:
    138
    Moving on with this topic...

    I've used the this.useGUILayout = false; on the FPS count script, and 2 things happened.

    1st, the FPS on the OnGUI didn't shown up anymore. And I'm not sure if that was what the useGUILayout was supposed to do.

    2nd, I've got this error that I have no Idea what does it mean.

    ArgumentException: Getting control 0's position in a group with only 0 controls when doing Repaint
    Aborting

    UnityEngine.GUILayout.Label (System.String text, UnityEngine.GUILayoutOption[] options) [0x00000] (at /Users/joe/iphone-clean/Runtime/Export/Generated/GUILayout.cs:10)[/code]
    FPS.OnGUI () (at Assets/Scripts/FPS.js:26)
     
  30. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    When you use useGUILayout=false, you're disabling the GUILayout system.

    Hence you need to switch from GUILayout.Whatever to GUI.Whatever - this also means you need to provide all positions yourself
     
  31. chips

    chips

    Joined:
    Nov 30, 2007
    Posts:
    138
    Ok! Thanks Nicholas, I believe that everything worked fine!
     
  32. RGAMESR

    RGAMESR

    Joined:
    Feb 10, 2017
    Posts:
    30
    ok , this happening to me now , and i dont know why , the profile didn't say anything...