Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

WebGL Threading

Discussion in 'Web' started by G33RT, Feb 19, 2021.

  1. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    52
    I understand that threading is not supported at this point for WebGL builds.... officially. However, I do know that there are/were builds out there that do allow some experimental support for it. What is the latest Unity version and with which settings could I get following minimalistic script running in WebGL?


    Code (CSharp):
    1. public class NewBehaviourScript : MonoBehaviour
    2. {
    3.     Text text;
    4.     volatile int counter = 0;
    5.  
    6.     void Start()
    7.     {
    8.         text = GetComponent<Text>();
    9.  
    10.         var t = new Thread(() =>
    11.         {
    12.             while (true)
    13.             {
    14.                 Interlocked.Increment(ref counter);
    15.             };
    16.         });
    17.  
    18.         t.Start();
    19.     }
    20.  
    21.     void Update()
    22.     {
    23.         text.text = counter.ToString();
    24.     }
    25. }
    I've tried various versions without succes till now. I am aware that following editor script must be present to enable it:

    Code (CSharp):
    1. using UnityEditor;
    2.  
    3. class ThreadSupport
    4. {
    5.     static ThreadSupport()
    6.     {
    7.         PlayerSettings.WebGL.linkerTarget = WebGLLinkerTarget.Wasm;
    8.         PlayerSettings.WebGL.threadsSupport = true;
    9.         PlayerSettings.WebGL.memorySize = 512;
    10.     }
    11. }
     
    Last edited: Feb 19, 2021
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,997
    Thread support is based on browser, so no mater what its not going to work everywhere even if you do get it working

    Secondly, please for the love of god use code tags when adding code to posts, its really unreadable in the current format you have added it
     
  3. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    52
    I'm trying on Firefox, Chrome and Safari on an M1 Mac. No luck till now...
     
  4. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Unfortunately there does not exist a combination of Unity and browser versions that would allow the above code to work. Multithreading C# is something that has not yet been deployed, because of pending C# language runtime development needs. Currently adding support for mobile devices and optimizing Unity to run lighter is at priority, hence multithreading has been pushed farther after mobile support first lands.
     
  5. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    52
    Ok. Would it be supported somewhere in the 2021.x.x versions this year? (even unofficially/experimental)

    I'm asking because it would impact our tech-stack of choice for a new product...
     
  6. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    There is a plan to re-deploy experimental native code multithreading back to Unity 2021.2 (no C# code multithreading)