Search Unity

DOTS Hybrid Sample for the wasm/browser target

Discussion in 'Entity Component System' started by EdRowlett-Barbu, Jan 19, 2020.

  1. EdRowlett-Barbu

    EdRowlett-Barbu

    Joined:
    Mar 16, 2015
    Posts:
    88
    This target is not officially supported at the moment, but it is still possible to get something running, with some sneaky workarounds. It took some weeks for me to figure out a workaround, so I'm hoping to save people some time by attaching a sample project that works.

    The gameplay is made using dots/ecs. Try to arrange the cubes to form the color sequences listed in the left panel, using as few cubes as possible.
    The animated character there is a gameobject, using the Animator system we all know and love.

    The Entities package had to be changed in one place to use some managed versions of methods instead of bursted methods, something I think project tiny does too. Thus you'll see the demo uses the Entities package as a local package, instead of the one downloaded through the package manager.
    And then you'll notice the sample uses systems that inherit from JobComponentSystem2, a wrapper I made to avoid a bug that exists currently with EntityCommandBuffer.Concurrent, causing memory leaks. Notice the job scheduling and ECB creation is done through this wrapper, to abstract away the fact that the wrapper chooses between using ECB directly, or ECB.Concurrent if the target platform supports it.
    The implementation is a messy proof of concept, and the wrapper causes some memory leak errors in the editor (which i didn't investigate yet), but works fine in the browser.

    Another thing to note is I tried building this with the scriptable build pipeline, which works if you try to build the Release target, but doesn't work if you try to build debug, it will fail with emscripten/posix_socket.h missing or some such (build script is Build/webgl in the project). Just build it the normal way using the Build Settings window in unity, that works even for development, or at least the exception call stacks are symbolicated.

    And another caveat is the project is using URP, which from what I understand is still a work in progress regarding browser compatibility.

    Excuse the messy and buggy code, it's a quick prototype I made to test the dots hybrid web target, but for whoever is crazy (brave?) enough to venture into this bleeding edge territory, hopefully it will save you some time.

    https://drive.google.com/open?id=1d8iypPYMiqNMWiBAsR21YYheZqGuv4-j
     
    Last edited: Jan 18, 2022
    maxostrach, Tomlinsky, DrViJ and 7 others like this.