Touch detection lag

Hi, everyone im developing my first unity app I have problem with the touch detection. It has a delay of 1-2 seconds. why is it slow? my apps stats are this Draw calls: 9 batched: 31 tris: 2.2k verts: 1.7k VRAM: 1.2 mb VBO: 63

I optimize the use of textures, most mesh shares same material. I compressed all of used textures. I really dont know whats wrong here, I followed suggestion in optimizing iphone app from other forums but still cant fix the lag and slow touch detection. I really need some help. anyone?

How are you doing touch detection, there no reason it should be slow given the details you have provided…

Do you have Unity Pro? You can use the profiler to check what thing drains the resources.
Also, please state out your situation clearly so that people can help you.
For an example:
You test the app by using unity remote or building it on the device?
What shaders are you using?
Incorrect use of for loop to get touches?

Check out appcontroller.mm to make it prioritise touches. But likely, you’re doing something you’re not realising is wrong like doing touches in fixedupdate or something.

You should set a state for touches and keep track if they’re on or off yourself, in update().

Whats the fps? if its 30 or above, its your code.

I use GetTouch(0) to get the tap position and instantiate an object in there. Yes im using unity pro 3, however I cant connect my device in the profiler because it doesn’t support ios yet. The shaders that I use are legacy lightmap for my scene and diffuse for other objects. I have 30 object scattered and visible. These object before have their own script where I always check their position on the update function. But I change this already because I think this was the reason that causes the lag. These object was also using mesh collider but as I have read from other forum mesh colliders are expensive so I changed it to just primitive colliders but still there is lag.

For the checking of touches I put it in the update() Is that wrong? sorry im still new to unity. fps is 60 but in may device is shows only 30. Hmm is it because of the object?

One thing that I think that causes the lag is the high number of batched? “Draw calls: 9 batched: 31” I dont know the maximum.

Thanks for replying.

So you mean you are using unity remote but not an actual iphone to test the game?
If this is true then the lag problem cannot be solved because unity remote uses wifi to communicate with the iphone.
The update of the screen is very slow in unity remote.

I did use the remote but not all the time because I know the update is very slow. I build my app on the ipod that where I saw the lag. I believed the update() function on my script which check for touches might be the cause. I experimented removing all other objects, platform, GUI and the gameObject where the touch detection script is attached from the scene and left one object animating back and forth no lag was visible. I cannot test the touch though because I removed the script.

  1. go to appcontroller.mm in your xcode file. expand the project and it is in the classes folder in xcode.
  2. in appcontroller.mm you will be able to set the FPS update to 60- do that now.
  3. in appcontroller.mm you are also able to enable caddisplaylink. Do that as well.
  4. in appcontroller.mm there is also an explanation of the timing methods you can use - simple comment out one and uncomment one that you feel will fix it.

Sometimes the rendering can be quite fast and the logic quite high. In situations like that, or the reverse, you can get issues where it isn’t responding to touches. You shouldn’t need to perform the above steps, but the real problem is most likely actually in your code.

Firstly, you should at the TOP of Update() stuff variables with the state of your touches. There is no point in constantly checking the fuctions and inputs for movement. This leads to bugs, lag and so on.

So… a simple guide:

function Update()
{

myTouchX = (get touches here code)
myTouchY = (get touches here code)
touch = true; etc etc
then in code, you refer to my myTouch variables instead.

}

This means when the system isn’t busy, the first thing it does is stuff myTouch with the data you need. There is no chance of getting crappy information later.

This might also be something to look into.
If the actual instantiation takes longer than you suspect, which it will, the culprit might be this rather than the touch code itself.

That’s a good point. It wouldn’t be noticed on the desktop. iOS prefers object pooling where possible so you could instantiate everything you wanted and just disable them until you needed them.

I preloaded the instantiated object and that fix the problem. I also found what was causing the lag. Its the colliders of the object in the scene, whenever collision is being check. I’ll limit the object to prevent this. Thanks for all your help guys.

Great to hear it solved, this will help other people with similar issues who enjoy using search buttons :slight_smile:

And oh how i do like using search. Thanks for the “simple guide” hippocoder.

Hey Hippo, curious as to why touches can’t be in FixedUpdate?
Thanks