Build Size Factors

Hey,

I am currently working on a WebGL project and, like everyone else, I really want to get the build size as small as possible. The compressed data is currently at 10.5 mb, which is not much, but still takes about 30 seconds to load including page freezes. I made a lot of test-builds today with varying configurations (Components & Settings) to see if there is anything I can throw out. You can see the results in the attached pdf.

Version: Unity 5.02f1 Pro

Now there’s a few things I don’t really understand:

  1. Why is there no difference between the three stripping levels?
    Thank you liortal, I looked over quite a few threads but did not see that.

  2. Does having a collider in the scene ‘add’ (or not strip) the entire physics engine/part?

  3. Why does an unassigned script affect the build size? It is not referenced in the scene, nor located in the resources folder. I thought Unity would only include stuff that is actually referenced somewhere or located in the resources folder?

  4. Why does the script below add 2.33 mb to the entire build size? Isn’t the ‘UnityEngine’ library always part of the build?

  5. If the new UI is written in C#, why does a custom script with ‘using UnityEngine.EventSystems’ add additional kb to the build size, given that I already have the EventSystem + Canvas + Button in the scene?

The magnificent script:

using UnityEngine;
using UnityEngine.EventSystems;

public class UnassignedClass : MonoBehaviour, IPointerClickHandler
{
    #region IPointerClickHandler implementation
    public void OnPointerClick (PointerEventData eventData)
    {
        // Stuff
        transform.position = eventData.worldPosition;
    }
    #endregion
}

Also, does Unity plan to add a web template that allows to load, unload the WebGL content on demand (play and close button), like the Sketchfab and Marmoset ‘viewers’ do?

Thanks!

2134556–140625–UnityWebGLTests.pdf (81.6 KB)

There’s no difference between the stripping levels in WebGL. This was mentioned in a few places and will probably be resolved in a future release.

1 Like

I can say as much as in the web player all scripts are compiled and included into the build. I assume this is so you can have an assetbundle that uses a script (the assetbundles does not contain the actual script but only its serialized values). I would assume that the WebGL version does the same in order to support the same approach.

Else you would have to make a system where the script is compiled and included in the assetbundle which would require assetbundles to have different targets for web gl and web player.

We strongly recommend to use 5.1 which includes some build size optimizations.

That’s because stripping works differently between Mono and il2cpp. We are in the process of changing the Stripping option to make it clearer to the user.

We try to strip as many modules of the engines as possible. If a collider is used, then we can’t strip PhysX.

That script might be used by an asset bundle

My guess is that by inheriting your class from IPointerClickHandler, parts (or all) of the UI system are not stripped.

normally what happens is that for most Unity subsystems there is a high level layer (in C#) and a low level one (C/C++). That’s also true for the UI. Maybe your script added a dependency to a Unity class that otherwise would have been stripped.

Do you really need a special WebGL template for that? What about loading a scene using the scripting API ?

@perlohmann , thanks for the reply! That makes sense, good to know!

@Marco-Trivellato , thank you for going through every point! I did update to 5.1 and the build was about 10% smaller, even without applying the new lossy texture compression. I think the tools mentioned in the roadmap post will also be very helpful, once available!

As for the web template, for any build that sits on a page with a lot of other content (text, images, lots of scrolling), the option to delay loading is a must, in my opinion. Especially when the process takes more than 20 seconds. But delaying the loading didn’t seem to difficult, so I’m fine. :slight_smile:

I didn’t look into unloading yet. Having the option, or a proper template would definitely be nice and improve the web-experience! For example:

  • when the canvas distracts from viewing other page content
  • a web-layout integrates the canvas in an accordion, tab, etc.
  • the canvas slows everything else down