Skip to content
Welcome to Spicy Pixel Answers, where you can ask questions and receive answers from the support team and other members of the community.

It doesn't work with WebGL but would it be possible to use non-threaded Tasks & Dispatchers?

0 votes

Unfortunately, it doesn't work with WebGL as of Unity 5.3.4.

"Currently, the JavaScript language does neither support multi-threading, nor SIMD. So, any code which benefits from these features will see bigger slowdowns then other code. You cannot write threading or SIMD code in WebGL in your scripts, but some engine parts are normally multi-threaded or SIMD optimized, and will run less performant on WebGL because of this. An example is the skinning code, which is both multi-threaded and SIMD-optimized. You can use the new timeline profiler in Unity to see how Unity distributes work to different threads on non-WebGL platforms. Longer term, we are hoping that these features will become available on WebGL as well."

It builds without errors (API Compatibility Level must be changed from .NET 2.0 subset to .NET 2.0) but when it runs, I get an error in the browser.

However, would it be possible to isolate only the single threaded dispatchers (e.g., fibers, coroutines) so we can still use it with WebGL?

related to an answer for: Can ConcurentBehaviour use in WebGL
asked May 11, 2016 in Concurrency Kit by danien (160 points)

1 Answer

+1 vote
Best answer

All of the Fiber and Fiber Task routines work on the main Unity thread and are in fact just coroutines.

Can you share stack trace with me so I can figure out where you're hitting the thread create?

Most likely you're not starting or continuing your fiber on a FiberScheduler, such as the one provided by a ConcurrentBehavior. See Unity Integration.

answered May 11, 2016 by admin (2,500 points)
selected May 13, 2016 by admin
Ah! I was using the ConcurrencyKitSample scene and built it for a WebGL target.

When I commented out the example code using the default schedulers and used the FiberScheduler, it built and ran without any issues.

Thank you!
Glad to hear that was it! And thanks for sharing that additional context. I should put a separate sample together demonstrating it.
I added a new release on GitHub that adds more support for Fibers and includes a sample for the WebGL target.