Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Out of options! Unity WebGL memory management. Some help please woud be nice!

Discussion in 'WebGL' started by MikaelKVS, May 18, 2018.

  1. MikaelKVS

    MikaelKVS

    Joined:
    Jan 9, 2018
    Posts:
    7
    Hi,

    Trying to load and process even one big file in WebGL build causes memory out issues.

    How can I override the default 2 gb limitation?
    I know about the warnings of using more than the default amount of memory.

    I have tried:
    Code (CSharp):
    1. PlayerSettings.WebGL.emscriptenArgs = " -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_MEM_MAX=4468435456";

    But build fails "Assets/PlayerSettingsOverride.cs(10,3): error CS0103: The name `PlayerSettings' does not exist in the current context". Works in editor thought. How should I modify the player settings via script.

    I tried changing amount of memory available from the Builds.json file and increasing memory size, but no luck there either.

    Don't know what problems Unity is facing with WebGL, but having fixed and hard coded memory size pretty much kills all the great ideas that requires scaling.
     
    Last edited: May 18, 2018
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,558
    Hi,
    what is the problem you are trying to solve?
    Does your content fails to start or it runs out of memory after a while?
     
  3. MikaelKVS

    MikaelKVS

    Joined:
    Jan 9, 2018
    Posts:
    7
    Hi and thanks for the fast reply,

    Problem is the memory management and trying to solve a case like "Client downloads a model bigger than than the 2 gigabytes" or "Client uses more than 2 gb of ram for working with a model inside Unity WebGL"

    Here is what happens:
    I start the application on Firefox -> Application starts downloading binary data -> web app starts processing vertices and related -> meshes and game objects are assembled. Eventually it crashes, with messages like use ALLOW_MEMORY_GROWTH=1 and increase amount of memory for the application.

    So in short the Unity app is dynamically creating arrays and lists for the data it downloads from server. Then processes it in to smaller pieces.
     
  4. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,558
    I am afraid you can't have a Unity Heap bigger than 2gb. It's a technical limitation.
     
  5. MikaelKVS

    MikaelKVS

    Joined:
    Jan 9, 2018
    Posts:
    7
    How would you handle scenario like this with Unity?
    Would you recommend sending the data outside Unity's heap(in the browser's frontend scripts)?
    https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html
    What would be the best way of doing this?
     
    Last edited: May 21, 2018
  6. JJJohan

    JJJohan

    Joined:
    Mar 18, 2016
    Posts:
    113
    It'd be pretty tricky to point at large quantities of data outside of Unity. You could take a look at what memory-heavy applications that also use Emscripten do, which is what Unity uses for conversion from C++ to asm.js/wasm. Similarly the 2gb limitation isn't Unity specific, it's moreso due to the existing JavaScript environment in browsers (A better explanation available here from someone with a similar question)

    Memory usage in WebGL has been a pretty big concern for me and my team because we deal with constant data streaming of images and point cloud data but we're managing pretty well with staying under 2GB. What are you trying to do in particular that would require a large size like that? You mention processing one big file is already exceeding your limit.
     
  7. MikaelKVS

    MikaelKVS

    Joined:
    Jan 9, 2018
    Posts:
    7
    AEC industry stuff. My concern is mostly in the thing that, I have worked with several 3d applications before and the memory size of those projects can get easily over 8 gb with tesselated models. Unity could be nice tool to show some content on the front-end, but I'm worried about the 2 gb heap size and the effects on productivity in development or that the work needed to get everything work nicely is too much to switch tools or consider Unity over something else.
     
  8. MikaelKVS

    MikaelKVS

    Joined:
    Jan 9, 2018
    Posts:
    7
    The problem was easily tackled with native WebGL by enabling int 64 bit arrays by khronos group approved extension. Problem is that the project is light ears away from Unity.
     
  9. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,558
    what do you mean by native WebGL?
     
  10. MikaelKVS

    MikaelKVS

    Joined:
    Jan 9, 2018
    Posts:
    7
    Thanks for replying,

    By native WebGL I mean writing everything from scratch with javascript using WebGL. After a some research both Unity and Unreal engine seems to use emscripten/webassembly to translate managed code with some pipeline to javascript. Current state seems to be that it supports 32 bit typed arrays, which seems to be the problem for limited heap size.

    In our case the situation is little bit problematic since switching to Unity would solve problems with developing tool for multiple platforms + save costs in development since you don't have reinvent wheels, but we would have to do a lot of work to get our stuff to work with web and the 2gb heap.

    It looks like I need to do more research if we could cache some of the data and do more processing on the cloud and wait for the 64 bit typed array support for emscripten.

    Been thinking of using something like world streamer to cache data that is not visible on the screen and to only stream LOD models that are currently visible.

    Anyone has any idea when emscripten would have support for 64 bit typed arrays or if it already have when would that version be available for Unity users?
     
    ina likes this.