Same Unity Project for WebGL and Android

Disclaimer:
if there was a general Platform forum section this thread should have been created there because it’s about two different platform. I posted here because with WebGL I’ve got quite less experience than with Android

Hi,
I’m working on a project that should be built for WebGL (run on a desktop browser only, not mobile) and Android.
Knowing that the are some differences between those two platform about requirements and available functionalities (as explained in the docs), do you think that I can still make them coexist easly (maybe using conditional compilation) or do I need to have separate projects?
For example for any REST api usually I use async/await, in this case can I still use it in WebGL being single thread or must I use coroutines?
Are there other big difference I should now of that I could encounter down the line?
For your information the project is not computationally/graphically demanding.

Thank you as always for your help

Bye

You generally work with one Unity project that exports to various platforms. Whatever platform-specific stuff you need to have can be configured via Player Settings and there you can also add scripting define symbols to include/exclude code.

In your case you only need to swap the method definition with an #if and you can do so by line-wrapping a method like so (from the top of my head, I hope it works):

public void
#if !PLATFORM_WEBGL
async
#endif
MethodName(Parameters params)
{
    // method body ...
}

It’s also common to create a custom build process to make scripted changes to each platform.

You can use async/await just fine on webgl builds. However, be mindful that even though Unity officially supports webgl, many things are just flat out broken or don’t work as expected/has issues.

I have many web assets that you can check.

Thank you guys for the help