Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Input.gyro issues on Android 7

Discussion in 'Android' started by mikewesthad, May 19, 2017.

  1. mikewesthad

    mikewesthad

    Joined:
    Oct 5, 2013
    Posts:
    16
    I just submitted this as a bug, but I figured I should probably cross-post this here to see if anyone is hitting the same issues:

    After updating my Samsung S6 to Android 7.0, my projects that relied on Input.gyro stopped working properly. The readings from Input.gyro.attitude and Input.gyro.userAcceleration appear to be lagging way behind the device's current angular position and acceleration. The readings from rotationRate and rotationRateUnbiased appear to be unaffected by this bug. Adjusting the updateInterval doesn't appear to help. (The gryoscope camera in Google Carboard's SDK is unaffected by this bug, presumably since it does not rely on Unity's Input.gryo.)

    For example, the script below should simply be taking the attitude from the gryo and using that as an object's rotation. If I throw this on a cube in a simple scene, the cube's rotation lags way, way behind the device's angular position. (See attached gif.)

    Any advice on debugging this? (I'm on Windows 10 & Unity 5.6.1f1.)

    Code (CSharp):
    1. public class GyroRotate : MonoBehaviour {
    2.     void Start () {
    3.         Input.gyro.enabled = true;
    4.     }
    5.     void Update () {
    6.         transform.rotation = Input.gyro.attitude;
    7.     }
    8.  
    9.     void OnGUI () {
    10.         GUIStyle style = new GUIStyle();
    11.         style.fontSize = Mathf.RoundToInt(Mathf.Min(Screen.width, Screen.height) / 20f);
    12.         style.normal.textColor = Color.white;
    13.         GUILayout.BeginVertical("box");
    14.         GUILayout.Label("Attitude: " + Input.gyro.attitude.eulerAngles, style);
    15.         GUILayout.Label("Rotation Rate: " + Input.gyro.rotationRate, style);
    16.         GUILayout.Label("Rotation Rate Unbiased: " + Input.gyro.rotationRateUnbiased, style);
    17.         GUILayout.Label("Acceleration: " + Input.gyro.userAcceleration, style);
    18.         GUILayout.Label("Gravity: " + Input.gyro.gravity, style);
    19.         GUILayout.EndVertical();
    20.     }
    21. }
    22.  
     

    Attached Files:

    • bug.gif
      bug.gif
      File size:
      1.1 MB
      Views:
      1,497
  2. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    what is your bugreport number?
     
  3. mikewesthad

    mikewesthad

    Joined:
    Oct 5, 2013
    Posts:
    16
  4. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    Thanks, I passed it to QA.
     
    wbknox likes this.
  5. mikewesthad

    mikewesthad

    Joined:
    Oct 5, 2013
    Posts:
    16
    Much appreciated!
     
  6. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,251
    I have just just discovered really laggy gyro on S6 (like low fps and poor quality tracking) which I am sure did not used to be the case - what is the status of this issue please, still awaiting a fix?

    BTW on S7 it is good.

    On S6 using the Google VR (GVR) asset it tracks the orientation perfectly using its native solution so will try and use that.

    S6 is SM-G920F, guessing this and the edge version of it are the ones affected
     
  7. mikewesthad

    mikewesthad

    Joined:
    Oct 5, 2013
    Posts:
    16
    As far as I know, the bug is still open (according to the issue tracker). I've been watching the patch releases, but I haven't seen any release notes that address it. Using the Google VR native solution is the way to go.
     
    andyz likes this.
  8. AxPetre

    AxPetre

    Joined:
    Jun 1, 2013
    Posts:
    96
    This might be a long shot, but did you tried with "Input.compensateSensors = true;"?
     
  9. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,251
    The Google VR native code returns far more accurate results than Unity's on an S7 too, so either unity is doing it wrong or it is smoothing the input resulting in lag (default gyro settings left on as any change tried did not change result)
    It does not help in setting up the gyro that none of the default values are mentioned for Input-gyro settings
     
    mikewesthad likes this.
  10. mikewesthad

    mikewesthad

    Joined:
    Oct 5, 2013
    Posts:
    16
    Thanks for the suggestion - but no dice on that fixing it.

    Good to know, but a bit of a bummer. Shot in the dark guess - Unity may be smoothing over time and/or integrating the gyro sensor results with other sensors.
     
  11. Nodrap

    Nodrap

    Joined:
    Nov 4, 2011
    Posts:
    83
    Just hit this exact same problem just now so it's still there and not fixed in 5.6.1f1
     
    mikewesthad likes this.
  12. Ignigomoreno

    Ignigomoreno

    Joined:
    Feb 10, 2015
    Posts:
    2
    Hey, I have the same issue as you mentioned. You suggest using google-vr as for the gyro data. How can I do that without seeing the google cardboard display?
     
  13. mikewesthad

    mikewesthad

    Joined:
    Oct 5, 2013
    Posts:
    16
    Just tested on Unity 2017.1.0f3 - still borked.
     
  14. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    We are aware of this. It's really a weird bug - we're just getting the updates from the native sensors with delay :(
     
  15. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    Hi there,
    Any luck i have also submitted my problem here

    I have also very leggy movement of gyroscope in
    Mobile: Samsung Galaxy S6
    OS: Andriod 7.0
    Unity: 5.2.1

    Please let me know when will you resolve this issue.?
     
  16. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    Its
    Its 16 Aug 2017, one after your last comment. Any luck?
     
    mikewesthad likes this.
  17. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    Yes its an issue i am also facing it. Thanks for posting.
     
  18. infrarosso

    infrarosso

    Joined:
    Jul 28, 2017
    Posts:
    1
    Any news about this issue?
     
  19. mikewesthad

    mikewesthad

    Joined:
    Oct 5, 2013
    Posts:
    16
    Still broken as far as I can tell. This makes Unity pretty unusable for any of my Android devices, despite 3D party libs like Google Cardboard working fine.
     
  20. 40kg

    40kg

    Joined:
    Dec 26, 2014
    Posts:
    1
    Can any one provide an package to fix this problem in android consult by Google VR SDK
     
  21. spacefrog

    spacefrog

    Joined:
    Jun 14, 2009
    Posts:
    734
    Still broken !

    And Ouch - that really hurts me currently developing for Galaxy S6/S7 using Unity 5.6.4P1
    It's really an important bug to fix !!!
    And setting Input.gyro.updateInterval does not show any effect ( always reporting 2E+10 ), so this is not only a sensor slow read error but something has to be generally broken in the unity core code as it seems
     
  22. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
  23. Neogene

    Neogene

    Joined:
    Dec 29, 2010
    Posts:
    94
    Seems no updates, we had this issue on a samsung J7, but on a Nokia 4 no. damn!
     
  24. Neogene

    Neogene

    Joined:
    Dec 29, 2010
    Posts:
    94
    Last edited: Apr 18, 2018
  25. NinjaCat

    NinjaCat

    R&D Minion

    Joined:
    Aug 22, 2013
    Posts:
    69
    Hi! The fix should also be in 2017.2.2p1, 2017.3.1p4 and up.
     
  26. Neogene

    Neogene

    Joined:
    Dec 29, 2010
    Posts:
    94
    We are using in 2017.4.1f1 and facing on J7 and A8 today, not in Nokia A4 and One Plus One.
     
  27. Neogene

    Neogene

    Joined:
    Dec 29, 2010
    Posts:
    94
    I developed also a NDK plugin to force change of sample ration of the gyro sensor without success hoping to fix it bypassing unity.
     
  28. NinjaCat

    NinjaCat

    R&D Minion

    Joined:
    Aug 22, 2013
    Posts:
    69
    That doesn't sound right. Could you please send us a bug report and post the case number here? A demonstration of the issue would also be really appreciated.

    One thing you could also try is going into the device test mode by dialing *#0*#. There should be a "Sensor" category. Could you tell us if the gyroscope sensor values are updating as expected or are they also lagging?
     
  29. Neogene

    Neogene

    Joined:
    Dec 29, 2010
    Posts:
    94
    The problem happens always (switching from vr to normal mode and starting app with normal ), we enable gyro using Input.gyro.enabled = true and we set frequency Input.gyro.updateInterval = 0.02f. Same happens when starting straight enabling gyro, update interval results in a 10-notation value:

    Example (sorry for the quality, same code on Nokia (first one, android v 7.1.1 kernel 3.18.35+) which goes well, one plus one too (Android 7.1.2 lineage 14.1.2018<omissis>), second brand new Samsung J7 (android version 7.0, kernel 3.18.14-12784722) which lags and client reported us a Samsung A8 lags too.

    Code is really simple,:

    Code (CSharp):
    1.   private float appliedGyroYAngle = 0f;
    2.  
    3.     private float calibrationYAngle = 0f;
    4.  
    5.     public float initialYAngle = 0f;
    6.     private float gyroFrequency = 0.02f;
    7.  
    8.      private void Start()
    9.      {
    10.          initialYAngle = transform.eulerAngles.y;
    11.    
    12.      Debug.Log("Starting Gyro update interval BEFORE SET AND ENABLING, current value: "+Input.gyro.updateInterval); //OK 0 value
    13.          Input.gyro.enabled = true;
    14.          Debug.Log("Starting Gyro update interval BEFORE SET AND ENABLED, current value: " + Input.gyro.updateInterval); //returns 2E+10
    15.          Input.gyro.updateInterval = gyroFrequency;
    16.          Debug.Log("Starting Gyro update interval AFTER SET AND ENABLED, current value: " + Input.gyro.updateInterval); //returns 2E+10
    17.  
    18.         Invoke("CheckUpdateIntervalDelayer", 1f);
    19.      }
    20.  
    21.     void CheckUpdateIntervalDelayer(){
    22.         Debug.Log("Updating Gyro update interval AFTER SET, current value: " + Input.gyro.updateInterval); //returns 2E+10
    23.     }
    24.  
    25.      void Update () {
    26.  
    27.         if (Input.gyro.enabled)
    28.         {
    29.             transform.rotation = Input.gyro.attitude;
    30.             transform.Rotate(0f, 0f, 180f, Space.Self);
    31.             transform.Rotate(90f, 180f, 0f, Space.World);
    32.             appliedGyroYAngle = transform.eulerAngles.y;
    33.  
    34.             transform.Rotate(0f, -calibrationYAngle, 0f, Space.World);
    35.         }
    36.      }
    37. }

    On "cardboard mode " gyro works without problems!

    Here, reading lines :

    when setting android ndk:

    I/Sensors: SENSOR : setDelayGyro 20000000(ns)

    ASensorEventQueue_setEventRate: handle=1, name=K6DS3TR Gyroscope, delay=20000, ret=0


    ANDROID DEBUG log:

    Code (CSharp):
    1.   (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/Android/runtime/DebugBindings.gen.cpp Line: 51)
    2. 2018-04-21 08:02:49.644 30162-30162/it.hartstudio.samsungbug D/ViewRootImpl@314b6d8[UnityPlayerActivity]: Relayout returned: oldFrame=[0,0][1920,1080] newFrame=[0,0][1920,1080] result=0x1 surface={isValid=true -459126784} surfaceGenerationChanged=false
    3. 2018-04-21 08:02:49.645 2987-3563/? D/WifiWatchdogStateMachine.NetworkStatsAnalyzer: 2 2 728 148 364 74
    4. 2018-04-21 08:02:49.651 2987-15358/? W/SensorService: sensor 00000000 already enabled in connection 0xb57f48a0 (ignoring)
    5. 2018-04-21 08:02:49.651 2987-15358/? I/Sensors: SENSOR : setDelayAcc 66667000(ns)
    6. 2018-04-21 08:02:49.651 30162-30209/it.hartstudio.samsungbug I/sensor: ASensorEventQueue_enableSensor: handle=0, name=K6DS3TR Accelerometer, ret=0
    7. 2018-04-21 08:02:49.651 2987-3883/? I/Sensors: SENSOR : setDelayAcc 20000000(ns)
    8. 2018-04-21 08:02:49.652 30162-30209/it.hartstudio.samsungbug I/sensor: ASensorEventQueue_setEventRate: handle=0, name=K6DS3TR Accelerometer, delay=20000, ret=0
    9. 2018-04-21 08:02:49.652 30162-30209/it.hartstudio.samsungbug D/Unity: Sensor :        Accelerometer ( 1) ; 0.001197 / 0.01s ; K6DS3TR Accelerometer / STM
    10. 2018-04-21 08:02:49.657 2987-3906/? I/MediaFocusControl:  AudioFocus  requestAudioFocus() from uid/pid 10192/30162 clientId=android.media.AudioManager$a7a2d05<native proxy object> req=1 flags=0x0 contentType=2
    11. 2018-04-21 08:02:49.657 30162-30209/it.hartstudio.samsungbug D/AudioManager: requestAudioFocus status : 1
    12. 2018-04-21 08:02:49.659 30162-30162/it.hartstudio.samsungbug D/ViewRootImpl@314b6d8[UnityPlayerActivity]: Relayout returned: oldFrame=[0,0][1920,1080] newFrame=[0,0][1920,1080] result=0x1 surface={isValid=true -459126784} surfaceGenerationChanged=false
    13. 2018-04-21 08:02:49.661 30162-30597/it.hartstudio.samsungbug I/AudioTrack: Skip ramp
    14. 2018-04-21 08:02:49.665 30162-30209/it.hartstudio.samsungbug D/Unity: Choreographer available: Enabling VSYNC timing
    15. 2018-04-21 08:02:49.669 30162-30609/it.hartstudio.samsungbug D/AudioTrack: Client defaulted notificationFrames to 709 for frameCount 2129
    16. 2018-04-21 08:02:49.670 30162-30609/it.hartstudio.samsungbug I/AudioTrack: This process already got info. FadeIn[0] FadeOut[0] FadeInRing[0]
    17. 2018-04-21 08:02:49.670 2706-2781/? W/AudioPolicyIntefaceImpl: Skipped to add effects on session 2473
    18. 2018-04-21 08:02:49.670 2706-2781/? I/APM_AudioPolicyManager: startOutput() output 13, stream 3, session 2473
    19. 2018-04-21 08:02:49.670 2706-2781/? I/AudioEffectStage: getBuffer primary_output_sub1_normal, 0xf3c0b000
    20.     getBuffer primary_output_sub1_normal
    21. 2018-04-21 08:02:49.671 30162-30610/it.hartstudio.samsungbug D/Choreographer: init sf_choreo_doframe   debug_Level : 0x4f4cdebug_game_running : false
    22. 2018-04-21 08:02:49.674 30162-30209/it.hartstudio.samsungbug I/Unity: Starting Gyro update interval BEFORE SET AND ENABLING, current value: 0
    23.     UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    24.     UnityEngine.Logger:Log(LogType, Object)
    25.     GyroLook:Start()
    26.  
    27.     (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/Android/runtime/DebugBindings.gen.cpp Line: 51)
    28. 2018-04-21 08:02:49.679 2987-3490/? I/Sensors: SENSOR : setDelayMag 20000000(ns)
    29. 2018-04-21 08:02:49.680 2987-3490/? I/Sensors: SENSOR : setDelayGyro 20000000(ns)
    30.     SENSOR : setEnableMag handle 2, en 1
    31. 2018-04-21 08:02:49.681 2706-2773/? I/AudioMixer: create resampler src 24000, 2, dst 48000, 2, q 8
    32. 2018-04-21 08:02:49.681 2706-2773/? D/SoundAliveResampler: [SoundAliveResampler] Init+++
    33. 2018-04-21 08:02:49.699 2987-3490/? I/Sensors: SENSOR : setEnableGyro handle 1, en 1
    34. 2018-04-21 08:02:49.699 30162-30209/it.hartstudio.samsungbug D/SensorManager: registerListener :: 1936879478, Samsung Rotation Vector Sensor, 20000, 0,
    35. 2018-04-21 08:02:49.700 30162-30209/it.hartstudio.samsungbug I/sensor: ASensorEventQueue_enableSensor: handle=1, name=K6DS3TR Gyroscope, ret=0
    36. 2018-04-21 08:02:49.700 30162-30209/it.hartstudio.samsungbug D/Unity: Sensor :            Gyroscope ( 4) ; 0.000611 / 0.01s ; K6DS3TR Gyroscope / STM
    37. 2018-04-21 08:02:49.700 2987-3883/? I/Sensors: SENSOR : setDelayGyro 20000000(ns)
    38. 2018-04-21 08:02:49.701 30162-30209/it.hartstudio.samsungbug I/sensor: ASensorEventQueue_setEventRate: handle=1, name=K6DS3TR Gyroscope, delay=20000, ret=0
    39. 2018-04-21 08:02:49.701 30162-30209/it.hartstudio.samsungbug D/Unity: Sensor :            Gyroscope ( 4) ; 0.000611 / 0.01s ; K6DS3TR Gyroscope / STM
    40. 2018-04-21 08:02:49.703 30162-30209/it.hartstudio.samsungbug I/sensor: ASensorEventQueue_enableSensor: handle=1936159350, name=Samsung Gravity Sensor, ret=0
    41. 2018-04-21 08:02:49.703 30162-30209/it.hartstudio.samsungbug D/Unity: Sensor :              Gravity ( 9) ; 0.001197 / 0.01s ; Samsung Gravity Sensor / Samsung Electronics
    42. 2018-04-21 08:02:49.704 30162-30209/it.hartstudio.samsungbug I/sensor: ASensorEventQueue_setEventRate: handle=1936159350, name=Samsung Gravity Sensor, delay=20000, ret=0
    43. 2018-04-21 08:02:49.704 30162-30209/it.hartstudio.samsungbug D/Unity: Sensor :              Gravity ( 9) ; 0.001197 / 0.01s ; Samsung Gravity Sensor / Samsung Electronics
    44. 2018-04-21 08:02:49.704 30162-30209/it.hartstudio.samsungbug I/sensor: ASensorEventQueue_enableSensor: handle=1936484718, name=Samsung Linear Acceleration Sensor, ret=0
    45. 2018-04-21 08:02:49.704 30162-30209/it.hartstudio.samsungbug D/Unity: Sensor :  Linear Acceleration (10) ; 0.001197 / 0.01s ; Samsung Linear Acceleration Sensor / Samsung Electronics
    46. 2018-04-21 08:02:49.705 30162-30209/it.hartstudio.samsungbug I/sensor: ASensorEventQueue_setEventRate: handle=1936484718, name=Samsung Linear Acceleration Sensor, delay=20000, ret=0
    47. 2018-04-21 08:02:49.705 30162-30209/it.hartstudio.samsungbug D/Unity: Sensor :  Linear Acceleration (10) ; 0.001197 / 0.01s ; Samsung Linear Acceleration Sensor / Samsung Electronics
    48. 2018-04-21 08:02:49.705 2987-27718/? I/Sensors: SENSOR : setDelayMag 34000000(ns)
    49. 2018-04-21 08:02:49.715 30162-30209/it.hartstudio.samsungbug I/sensor: ASensorEventQueue_enableSensor: handle=1936879478, name=Samsung Rotation Vector Sensor, ret=0
    50. 2018-04-21 08:02:49.715 30162-30209/it.hartstudio.samsungbug D/Unity: Sensor :      Rotation Vector (11) ; 0.000000 / 0.01s ; Samsung Rotation Vector Sensor / Samsung Electronics
    51. 2018-04-21 08:02:49.715 2987-29349/? I/Sensors: SENSOR : setDelayMag 20000000(ns)
    52. 2018-04-21 08:02:49.724 30162-30209/it.hartstudio.samsungbug I/sensor: ASensorEventQueue_setEventRate: handle=1936879478, name=Samsung Rotation Vector Sensor, delay=20000, ret=0
    53. 2018-04-21 08:02:49.724 30162-30209/it.hartstudio.samsungbug D/Unity: Sensor :      Rotation Vector (11) ; 0.000000 / 0.01s ; Samsung Rotation Vector Sensor / Samsung Electronics
    54. 2018-04-21 08:02:49.726 30162-30209/it.hartstudio.samsungbug I/Unity: Starting Gyro update interval BEFORE SET AND ENABLED, current value: 2E+10
    55.     UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    56.     UnityEngine.Logger:Log(LogType, Object)
    57.     GyroLook:Start()
    58.  
    59.     (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/Android/runtime/DebugBindings.gen.cpp Line: 51)
    60. 2018-04-21 08:02:49.726 2987-27328/? I/Sensors: SENSOR : setDelayGyro 20000000(ns)
    61. 2018-04-21 08:02:49.727 30162-30209/it.hartstudio.samsungbug I/sensor: ASensorEventQueue_setEventRate: handle=1, name=K6DS3TR Gyroscope, delay=20000, ret=0
    62. 2018-04-21 08:02:49.727 30162-30209/it.hartstudio.samsungbug D/Unity: Sensor :            Gyroscope ( 4) ; 0.000611 / 0.01s ; K6DS3TR Gyroscope / STM
    63. 2018-04-21 08:02:49.727 30162-30209/it.hartstudio.samsungbug I/sensor: ASensorEventQueue_setEventRate: handle=1936159350, name=Samsung Gravity Sensor, delay=20000, ret=0
    64. 2018-04-21 08:02:49.727 30162-30209/it.hartstudio.samsungbug D/Unity: Sensor :              Gravity ( 9) ; 0.001197 / 0.01s ; Samsung Gravity Sensor / Samsung Electronics
    65. 2018-04-21 08:02:49.727 30162-30209/it.hartstudio.samsungbug I/sensor: ASensorEventQueue_setEventRate: handle=1936484718, name=Samsung Linear Acceleration Sensor, delay=20000, ret=0
    66. 2018-04-21 08:02:49.727 30162-30209/it.hartstudio.samsungbug D/Unity: Sensor :  Linear Acceleration (10) ; 0.001197 / 0.01s ; Samsung Linear Acceleration Sensor / Samsung Electronics
    67. 2018-04-21 08:02:49.727 30162-30209/it.hartstudio.samsungbug I/sensor: ASensorEventQueue_setEventRate: handle=1936879478, name=Samsung Rotation Vector Sensor, delay=20000, ret=0
    68. 2018-04-21 08:02:49.727 30162-30209/it.hartstudio.samsungbug D/Unity: Sensor :      Rotation Vector (11) ; 0.000000 / 0.01s ; Samsung Rotation Vector Sensor / Samsung Electronics
    69. 2018-04-21 08:02:49.728 30162-30209/it.hartstudio.samsungbug I/Unity: Starting Gyro update interval AFTER SET AND ENABLED, current value: 2E+10
    70.     UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    71.     UnityEngine.Logger:Log(LogType, Object)
    72.     GyroLook:Start()
     
    Last edited: Apr 22, 2018
  30. Monstermash28425R1

    Monstermash28425R1

    Joined:
    Sep 8, 2016
    Posts:
    9
    soyy 5.6.7f1 and i get some worst error than yours, im developing to Moto G5, its have gyro and google cardboard app work fine!, but Input.gyro.attitude doesn't work, it just return an attiture of (0,0,0,1), some suggestion? ive downloaded a game made in unity with a older version working with google vr and my gyro works fine, some error with unity and newer android version devices? im on android 8.1 btw, hope you can help us!