What you might not realize is that this virtual filesystem is loaded into and persisted in memory as soon as your Unity application starts. Any time you cache an asset bundle or use any filesystem-related methods, they are stored in a virtual filesystem backed by IndexedDB. In this example, you can see that our application is requesting a whopping 256MB (the default) for the heap, when we really should be requesting about 32MB:Īsset Bundles & IDBFS: The Silent KillersĪnother source of memory-related problems is the IndexedDB filesystem used by Unity. You should use this tool to keep track of the highest amount of memory used, and then add a safety net on top of that while rounding up to the next highest 16MB. However, it is still crucial as a tool for measuring and tuning how much memory to allocate for your Unity heap. That is, when objects are cleaned up, the used/free memory does not change. It is important to note that the data Unity/Emscripten provides here appears to be a high watermark for memory usage. Simply import the package into your Unity project, add the “WebGL Memory Stats” script to a GameObject in your scene, and log entries about free/total memory will be made in your browser console at an interval of your choosing: Since reducing the size of your Unity heap is so important, we have added a very simple memory stats class (based on the Unity team’s excellent blog) to our WebGL utilities package in order to help developers track this information and report it to the browser console. To reiterate, the less memory you need to reserve for the Unity heap, the more memory the browser will have available for other things such as audio, IndexedDB databases, etc. The first is the Unity heap, which defaults to 256MB and can be changed in the Publishing Settings interface under “WebGL Memory Size.” We touched on some optimization techniques for this chunk of memory (and why you want to keep it as small as possible) in a previous blog post. When profiling and optimizing your Unity WebGL game, it is important to keep track of multiple kinds of memory usage. This article will cover some more tips and tricks for diagnosing and resolving memory-related issues with your Unity WebGL game. This is a particularly frustrating issue for players using 32-bit versions of browsers, since they are much less likely to have a large contiguous block of free memory for the Unity heap. The main pain point that we hear from developers relates to the dreaded “out of memory” errors that end users encounter when trying to play WebGL games. Now that the Unity WebPlayer is mostly a thing of the past, making sure your Unity WebGL content runs smoothly is more important than ever.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |