Search Unity

GvrFPSCanvas doesn't work when GvrController is used

Discussion in 'Daydream' started by wojwen, Sep 24, 2016.

  1. wojwen

    wojwen

    Guest

    I added GvrFPSCanvas to my scene and it was working fine until I added simple script which checks controller status (it's from this page) and it looks like this:
    Code (CSharp):
    1.     public GameObject statusCanvas;
    2.     public Text statusText;
    3.  
    4.  
    5.     void Update() {
    6.  
    7.         switch (GvrController.State) {
    8.             case GvrConnectionState.Connected:
    9.                 Time.timeScale = 1;
    10.                 statusCanvas.SetActive(false);
    11.                 break;
    12.             case GvrConnectionState.Disconnected:
    13.                 statusText.text = "Waiting for controller...";
    14.                 statusCanvas.SetActive(true);
    15.                 Time.timeScale = 0;
    16.                 break;
    17.             case GvrConnectionState.Scanning:
    18.                 statusText.text = "Scanning for controller...";
    19.                 statusCanvas.SetActive(true);
    20.                 Time.timeScale = 0;
    21.                 break;
    22.             case GvrConnectionState.Connecting:
    23.                 statusText.text = "Connecting to controller...";
    24.                 statusCanvas.SetActive(true);
    25.                 Time.timeScale = 0;
    26.                 break;
    27.             case GvrConnectionState.Error:
    28.                 statusText.text = "ERROR: " + GvrController.ErrorDetails;
    29.                 statusCanvas.SetActive(true);
    30.                 Time.timeScale = 0;
    31.                 break;
    32.             default:
    33.                 statusText.text = "Unknown status.";
    34.                 statusCanvas.SetActive(true);
    35.                 Time.timeScale = 0;
    36.                 break;
    37.         }
    38.  
    39.         transform.localRotation = GvrController.Orientation;
    40.  
    41.     }
    After doing this GvrFPSCanvas displays this message: NaN msf (-2147483648 FPS). If i disable this script it works just fine again. Have you encountered this as well? Did you find any solution?
     
  2. FocalPoint

    FocalPoint

    Joined:
    Jul 2, 2016
    Posts:
    1
    The GvrFPS script uses Time.deltaTime, so if you adjust your Time.timescale to 0, deltaTime will be 0 and cause a divide by zero error in LateUpdate(). This also means if you set your timescale to be any value other than 0, the displayed FPS will be scaled by that amount and will not be accurate. You could try editing the GvrFPS.cs script to replace Time.deltaTime with Time.unscaledDeltaTime, or replace the entire LateUpdate() function with your own FPS algorithm.
     
  3. wojwen

    wojwen

    Guest

    Yes you are right. This is the part of code that causes problems:
    Code (CSharp):
    1.     float interp = Time.deltaTime / (0.5f + Time.deltaTime);
    2.     float currentFPS = 1.0f / Time.deltaTime;
    3.     fps = Mathf.Lerp(fps, currentFPS, interp);
    Basically when Time.deltaTime is set to 0 fps beacomes minimum int value (–2,147,483,648) and after that it doesn't change because it lerps between this and current fps. And as mattrosen said changing Time.deltaTime to Time.unscaledDeltaTime fixes the problem. I think that it's a bug that needs to be fixed in next sdk update.
     
  4. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    400
    Thanks, we've reported this to google.