Framerate drops when screen is touched

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.

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.

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.

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.

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.

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?

Awake is enough

Is this going to be rolled into Unity 2.x proper? It seems like a great optimisation feature to have in general :slight_smile:

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…

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…

do I place useGUILayout in every script or just one? I don’t really understand how and where to put this.

Put it in the Awake() function of every script that has an OnGUI() function.

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.

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.

I get this error:

Assets/_Scripts/Mode Manager.js(10,23): BCE0020: An instance of type 'UnityEngine.MonoBehaviour' is required to access non static member 'useGUILayout'.

as said above, how do i use it?

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.

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.

That fixed all my lag problems! Nice!

useGUILayout only does something when you have a OnGUI call on the same script.