0
\$\begingroup\$

I want to make buttons for a mobile build, testing with android 11. To set variables, which I read in other scripts, I use the following code:

foreach (Touch touch in Touch.activeTouches)
    {
        Vector2 pos = touch.screenPosition;

        if (player.leftRect.Contains(pos))
            input = -1f;

        if (player.rightRect.Contains(pos))
            input = 1f;

        if (player.jumpRect.Contains(pos))
        {
            jumpHeld = true;
            if (touch.phase == TouchPhase.Began)
                jumpPressed = true;
        }

        if (player.dashRect.Contains(pos) && touch.phase == TouchPhase.Began)
            dashPressed = true;
    }

With the rects being set from rectTransforms in Start(). This snippet gets called in Update. However, when on the build, every press is delayed 200-300ms.

I tried using the new InputSystem Unity provides, however that only increased the latency to around 500ms.

Lots of other games run smoothly on this phone, so are there any fixes or best practices one should do?

\$\endgroup\$
2
  • \$\begingroup\$ This code will not be the source of that latency. You have an unnecessary allocation when accessing activeTouches, but that wouldn't account for 200-500ms. It's likely you have some latency introduced in the code that acts on this, or your game is overwhelming the phone's processing and the update ticks are falling behind realtime. \$\endgroup\$ Commented Jun 7 at 23:15
  • \$\begingroup\$ What framerate is the application running at? How are you measuring the input latency? What device are you using? Note that some old and low-end devices have very high input latency. \$\endgroup\$ Commented Jun 13 at 17:50

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.