Search Unity

[bug] 360 Video Freezing On First Click (loading Ui Elements)

Discussion in 'AR/VR (XR) Discussion' started by Dighim, Apr 10, 2019.

  1. Dighim

    Dighim

    Joined:
    Apr 10, 2019
    Posts:
    4
    Hello everyone,

    After 2 days of searching without response I'm exposing my problem to you.

    My app is running on Android with Google Cardboard and consists in playing a 360 video as the skybox with some collider moving with animations. The user is able to aim at a collider and "click" to get some informations.

    The problem is that in editor mode it works perfectly fine but once I run it on Android the video freezes on the first click for like 2 seconds and then resume. Clicks after it doesn't reproduce the effect.

    The click is showing product pictures one after the other (2-3) and also a text.

    So the UI is essentially composed of 2 images and a TextMeshPro.

    I've already had this issue which I resolved before and was cause by enabling or disabling text that I resolved by only putting text to empty string (""). I suppose that it's now due to the image and I tried many things such as :

    - Instead of creating a new Sprite for image, I now just take the picture remotely and apply the texture to the raw image

    - As I read this on the forum, I did split my canvas into 3 different ones since I read that canvas were redrawing all elements on each change

    - I tried different phones (Galaxy S5 - S7) and did not work

    - Tried to look the profiler on the first click and the most resource-consuming is lighting and I'm not sure that the problem comes from there (or maybe)

    Here the code concerning my click event. Not sure that's the way to put down code on the forum sorry :

    Code (CSharp):
    1. // Update is called once per frame
    2.     void FixedUpdate()
    3.     {
    4.         if (Input.GetMouseButtonDown(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began))
    5.         {
    6.             RaycastHit hit;
    7.             if (Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity))
    8.             {
    9.                 StartCoroutine(someUrlWithId);
    10.  
    11.                 if (decadeCoroutine != null)
    12.                 {
    13.                     StopCoroutine(decadeCoroutine);
    14.                 }
    15.  
    16.                 decadeCoroutine = StartCoroutine(DecadeTextAfterTime(2));
    17.                 hitText.text = "You selected a model";
    18.             }
    19.         }
    20.     }
    21.  
    22.     IEnumerator GetRequest(string uri)
    23.     {
    24.         Dictionary<string, string> content = new Dictionary<string, string>
    25.         {
    26.             //Fill key and value
    27.             { "property", "property" },
    28.         };
    29.  
    30.  
    31.         UnityWebRequest uwr;
    32.         uwr = UnityWebRequest.Post(SomeTokenUrl);
    33.         uwr.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    34.         uwr.SetRequestHeader("Authorization", Env.BASICAUTH);
    35.         yield return uwr.SendWebRequest();
    36.  
    37.         if (uwr.isNetworkError || uwr.isHttpError)
    38.         {
    39.             Debug.Log("Error While Sending: " + uwr.error);
    40.         }
    41.         else
    42.         {
    43.             TokenClassName token = JsonUtility.FromJson<TokenClassName>(uwr.downloadHandler.text);
    44.  
    45.             uwr = UnityWebRequest.Get(uri);
    46.             uwr.SetRequestHeader("Authorization", "Bearer " + token.access_token);
    47.             yield return uwr.SendWebRequest();
    48.  
    49.             if (uwr.isNetworkError || uwr.isHttpError)
    50.             {
    51.                 Debug.Log("Error While Sending: " + uwr.error);
    52.             }
    53.             else
    54.             {
    55.                 SomeModel someModel = JsonUtility.FromJson<SomeModel>(uwr.downloadHandler.text);
    56.  
    57.                 if (changeProduct != null)
    58.                 {
    59.                     StopCoroutine(changeProduct);
    60.                 }
    61.                 yield return changeProduct = StartCoroutine(ChangeProductImage(someModel.products, 0));
    62.             }
    63.         }
    64.     }
    65.  
    66.     IEnumerator ChangeProductImage(List<Product> products, int idx)
    67.     {
    68.         if(idx != 0)
    69.         {
    70.             yield return new WaitForSeconds(2);
    71.         }
    72.         WWW www = new WWW(products[idx].content.picture);
    73.         yield return www;
    74.         productImage.texture = www.texture;
    75.         productImage.color = Color.white;
    76.         if (idx == products.Count - 1)
    77.         {
    78.             yield return new WaitForSeconds(2);
    79.             productImage.color = Color.clear;
    80.         }
    81.         else
    82.         {
    83.             yield return ChangeProductImage(products, idx + 1);
    84.         }
    85.     }
    86.  
    87.     IEnumerator DecadeTextAfterTime(int Time)
    88.     {
    89.         yield return new WaitForSeconds(Time);
    90.         hitText.text = "";
    91.     }
    Please I'm desperate, any help would be greatly appreciated as I'm fairly new to Unity (1 week).