Unity Touches (mouse clicks) but _NOT_ in Update

Hello. this is probably lame, but I could not find a solution yet.
Is it possible to detect touches in Unity outside of Update function which can be inconsistent during slowdowns, leading to skipped touches?

I would like to implement some kind of touches queue that releases everything with the next updated frame.

Update runs every frame which is every loop the engine makes… you’re basically asking for some way of doing things “between” the frames when the frames are being slow… which makes no sense. You can’t process code faster than the code is being processed.

Probably worth fixing the slow down issues rather than trying to work around them.

1 Like

ok. one thing will clear everything up.
situation: app runs with target fps 30, user touched and released the screen really fast in 33ms interval. Will this event be registered with the next update on (Input.GetMouseButtonDown(0))?

With “only” 30FPS on a device you shouldn’t be that worried about when a very very short touch isn’t recognized. When your app runs with 60 FPS you shouldn’t have any problems.
but as far as i know Input recognition is directly before the Update, so you will not get any better result as with Update().

And like @LeftyRighty said, Update is called every frame and it’s no code done between. So higher FPS better Results.

Just for the example
iPad3 on-screen keyboard suffers sometimes from massive slowdowns during backgroipund iOS downloads or other circumstances. There’s like 1-2 seconds delay between touch and key registration.
But any amount of keys you’ve entered will eventually be registered in correct order.
It looks like Unity will just skip inputs during slowdowns, heavy loads (also directly after) and all situations leading to dropped frames. You have to hold your finger until next update, that is what user will not do every time. This is mostly topical for older devices.
There are probably more optimization and longer pre-loads should be done, but some things are just out of my jurisdiction.

The values in the Update class is updated on every Update. If the user presses the A key after frame 25 has started, Input.GetKeyDown(KeyCode.A) will be true when frame 26 starts, and stop being true again when frame 27 starts.

The only time input gets inconsistent is if you try to read it in FixedUpdate. Physics frames run out of sync with Update frames - depending on your framerate, there might be 0, 1 or several FixedUpdates between frame 26 and 27. Because of this, never read input from the Input class in FixedUpdate.

If you’re reading input during Update and it’s failing, that’s probably a bug.

1 Like

you’ll probably find the keyboard is asynced and buffered so the application can just “get next input” in order if the buffer has more than one input waiting on request… basically the keyboard is running every frame even if the input isn’t being consumed every frame… not quite the same situation within an unity app where the input and the processing is all happening together… unless you write an asynced input class I guess.

1 Like