Search Unity

Touch lag HELP!!!!!! :(

Discussion in 'Android' started by bryphi77, Jul 13, 2017.

  1. bryphi77

    bryphi77

    Joined:
    Jul 4, 2017
    Posts:
    3
    Hi guys... I am hoping that someone can give me a better answer than the ones I have already found on the net and here.
    I am currently recreating a game I made in Processing in unity, and the performance for the touches is unusable for the game I have made. In processing the touches are near instant, in unity even the slightest movement will cause a lag. Just from looking at it... It seems that some sort of smoothing is being done by unity, whatever the reason, I need to find a way to fix it or Unity will be unusable for my game, and I will have to go with a native Java build. What really sucks is that I have already did so much work (nearly completed the game) before I decided to implement the multiple touch system.
    I am really hoping that someone has an answer for me, but judging by what I have seen already on the net, I may have just wasted 1 month of my life.
     
    Last edited: Jul 13, 2017
  2. DalerHakimov

    DalerHakimov

    Joined:
    Mar 14, 2014
    Posts:
    302
    How do you get your inputs?

    To get input from user, you have to use Update function.
    To do something with that input, you have to use FixedUpdate function.

    You have lags, because your code/game is not optimized, maybe you are running too much of things in your scene. Use profiler and debug it.
     
  3. bryphi77

    bryphi77

    Joined:
    Jul 4, 2017
    Posts:
    3
    I have read every thread and documentation about it on the net... Along with all the native android java docs when I made the game originally...
    The issue can be seen on a very simple test dragging one sprite using update with touchphase moved.
    The motion is not jerky at all. It is a very smoothed lag that trails behind the actual finger. If it was related to the update I would be getting jumpy motion and that is not the case.
    Also, I am a fairly sure for my needs I dont want the movement to take place in fixed update, as I am not using physics, and need the motion to be accurate on every frame. I have tried it every which way at this point, and I get the best result using Update to move my point positions directly when not using physics.

    Honestly, the motion looks good, it would work fine for about 80% of the stuff I need to do, but this particular effect needs to be really responsive, and I had no issues when using the android sdk directly. I am not at all trying to bash Unity... I love this program. I have been using it for 12 hours a day for the past few months. It has been a very VERY GOOD experience up until I ran into this issue.

    If you have other info that may help please do share...
     
  4. DalerHakimov

    DalerHakimov

    Joined:
    Mar 14, 2014
    Posts:
    302
    Remove Time.DeltaTIme if you use it in your movement.
    Try using physics and use velocity for your movements.

    This is a problem, when you get your inputs and you want to make a move, you will be out of sync with refresh rate of the screen. Which means GPU doesn't handle it fast enough. So, I would actually consider using physics or add your movements in FixedUpdate.
     
  5. bryphi77

    bryphi77

    Joined:
    Jul 4, 2017
    Posts:
    3
    I am not using delta time because I am not moving it with my own physics calc (pos += vel ) With something like that I would use delta time, but I am just trying to lock something to the touch position directly. It needs no motion or physics other than being locked to the touch. When I use FixedUpdate for this I get jumps in motion do to the input being calculated every frame, but not the movement of the object.
    Like I said... The motion is silky smooth, no jumping or glitching. It looks good, but it does not follow as closely as it did on the native java build.

    After further testing, I am still going to finish the game in unity. Everything still works as it should... it is just that visually there is a lag. All inputs are still registered and I dont think it will hurt game play that much. I am using physics for my projectiles and collisions and they work fine. This is for a type of gun/ sling shot that appears when the user touches the screen, and is drawn back when the user slides their finger. The issue was much more noticeable in my tests when moving larger objects, but when I tested it with the actual game object it was usable, but it does lag more than I would have liked.

    Thanks for taking the time to help... I will try your suggestions... again ;)
     
  6. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    This is true. Unity's polling-based Input API (
    Input.touches
    /
    Input.GetTouches
    , you ASK for the data) has a drawback.

    In native Android, we receive touches via callbacks (may happen much more often than 60FPS frame rate) but in Unity, we ask the touch to use in-frame by
    Input.GetTouches


    What is in the
    Input.GetTouches
    right now is an interpretation of all native callbacks that happened before this frame. And so what you get from Unity is not necessary a present data. (Usually 1 frame late from the actual callback)

    Moreover, some data are lost (could be thought as the "processing" you mentioned) because callbacks can be more than once per finger per frame. But Unity has to present exactly 1 data per frame (per finger). Some processing is required to conform with data polling based API. And it is different on iOS and Android.

    Look at this log comparing native callbacks with what you can check from Unity's API every frame. 9 callbacks became 3 data and the other 6 are lost with no relationship to what you get from Unity. (The circled with arrow ones became exactly what you get from Unity, with delta delta-ed to the previous ones skipping the rest, which I marked X)

    androidvs2.png

    Of course, you still can only update your object in-frame. But with native callbacks you would have more data Unity discarded to work on. (You can do your own bezier interpolation from them, etc.)

    (If you would like to receive native callbacks then you might be interested in Native Touch )

    (Also if you just want to know how Unity interpret native callbacks into
    Input
    API on both iOS and Android you can read my own deduction here : http://exceed7.com/native-touch/callback-details.html)