Search Unity

Question Await delay.task blocks the browser

Discussion in 'Web' started by tonkodonis, Jan 7, 2023.

  1. tonkodonis

    tonkodonis

    Joined:
    Aug 21, 2022
    Posts:
    5
    Ho Everyone,
    First of all, sorry in advance as I am completely new to programming/unity/this forum... I am trying to learn all by myself from scratch for fun, going through all the materials and q&a on the web, but this time I might be stuck as I was not able to find any helpful answer (but sorry if it was somewhere...).

    So I developed a very basic "game" just to learn/practice, and I wanted to publish it in webGL format so it can be played from a browser (note that during development my "build setting" was set on Windows platform and I switched to WebGL before building), the problem is that on both unity play and itch.io, it looks like as soon as I reach a "await Task.Delay", the browser blocks...

    I checked the browser console that says when the game opens "WebGL warning: clientWaitSync: ClientWaitSync must return TIMEOUT_EXPIRED until control has returned to the user agent's main loop. (only warns once)". That must be it, should be an easy fix but I was unable to find out how to resolve this in my code/unity...

    if you have any clue that would be much appreciated.

    Anyways, many thanks to the whole community, I wouldn't have come that far without all the answers you provide on various forums.

    Here is a link to my game on unity play: https://play.unity.com/mg/other/my-game-that-does-not-work


    And the code where the issue seems to be:

    Code (CSharp):
    1.     public async void SetPlayerName()
    2.  
    3.         {
    4.         if(firstP == true)
    5.             {
    6.                 PS = PlayerStats.GetComponent<PlayerStats>();
    7.                 PS.Player1name = input;
    8.                 PS.activePlayer = PS.Player1name;
    9.                 PS.PlayerStatsUpdate();
    10.                 Player1nameEntered.text = PS.Player1name;
    11.                 iTween.ScaleTo(Player1Container, iTween.Hash("x", 4.0f, "y", 4.0f, "time", 1));
    12.                 GetComponent<AudioSource>().PlayOneShot(NameAppear);
    13.                 await Task.Delay(2000);
    14.                 FightImage.SetActive(true);
    15.                 iTween.ScaleTo(FightImage, iTween.Hash("x", 2.0f, "y", 2.0f, "time", 1));
    16.                 GetComponent<AudioSource>().PlayOneShot(FightAudio);
    17.                 inputfieldname.Select();
    18.                 inputfieldname.text = "";
    19.                 txt.text = "Enter Name of Second Player";
    20.                 firstP = false;
    21.                 Debug.Log(firstP);
    22.                
    23.             }
    24.         else if(firstP == false)
    25.             {
    26.                 PS = PlayerStats.GetComponent<PlayerStats>();
    27.                 PS.Player2name = input;
    28.                 PS.PlayerStatsUpdate();
    29.                 Player2nameEntered.text = PS.Player2name;
    30.                 iTween.ScaleTo(Player2Container, iTween.Hash("x", 4.0f, "y", 4.0f, "time", 1));
    31.                 GetComponent<AudioSource>().PlayOneShot(NameAppear);
    32.                 await Task.Delay(5000);
    33.                 RolltheDiceBox.SetActive(true);
    34.                 iTween.MoveTo(MessageBox, EndPanel.transform.position, 3.0f);
    35.                 await Task.Delay(3500);
    36.                 MessageBox.SetActive(false);
    37.                
    38.                
    39.             }
    40.         }
     
  2. tonkodonis

    tonkodonis

    Joined:
    Aug 21, 2022
    Posts:
    5
    I should have added that in development, the game works perfect
     
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,882
  4. kdchabuk

    kdchabuk

    Joined:
    Feb 7, 2019
    Posts:
    50
  5. Mariukh_Viacheslav

    Mariukh_Viacheslav

    Joined:
    Jul 4, 2022
    Posts:
    3