Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Bug (Case 1397607) Unity doesn't strip unused packages from builds

Discussion in '2022.1 Beta' started by KamilCSPS, Jan 24, 2022.

  1. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    448
    Using Unity 2022.1.0b3 (b4 WebGL building is broken)

    As more and more packages are included into the 'core', there is now an increased amount if assets, scripts and dependencies that get into the builds without them being used by the app.

    In this example, I am attempting to create a build without the legacy uGUI so I can build projects with only UIToolkit. Both are "Core" - why have 2 UI frameworks? More specifically, I am targeting WebGL because build size is very important on that platform and build times (iteration times) are long.

    Unfortunately, among uGUI, I am noticing that I am unable to just strip the packages from the build in a default empty project.

    Please advise.

    ---

    1. What happened
    As per https://docs.unity3d.com/2022.1/Documentation/Manual/ReducingFilesize.html, Unity should strip packages and assets that are not in-use. This is particularly important when exporting in WebGL.

    In the attached repro project, attempting to only use UIToolkit as the UI solution is impossible as Unity includes the legacy UI renderer. Additionally, the visualscripting and test-framework packages are also included in the build even though they are not in-use in the project.

    Packages/com.unity.visualscripting
    Packages/com.unity.test-framework
    Packages/com.unity.ugui

    2. How can we reproduce it using the example you attached
    - Create empty URP template project
    - Remove UI, test-framework, visual scripting packages in the project via package manager
    - Create and add a UIToolkit UIDocument to a gameobject
    - Build (Clean build) to WebGL
    - Open Editor.log
    - Notice legacy UI & other packages being included
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    You could go to the built-in tab of the Package Manager and remove the "UI" package. If you hit "View documentation" on that, it goes here, so I think it's why you're getting the uGUI code in the build.

    Problem is, of course, that there's some pretty gnarly dependencies. If you check "used by", it turns out that packages that depend on UI include: Input System (the new one), UI Elements and UI Toolkit (what the F***?), Universal RP (double what the F***?).
    That's in 2020.3, though, it might have been improved in 2022!
     
  3. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    448
    Yes, I noticed. I purposely made the scope of this report a big larger to be able shine a bit of light on this issue.

    The fact that the new input system has deep decencies with various packages is worrisome and contributes to not only instability (why would a URP update break the input system? or a UI Element change affect UIToolkit?) but also contributes to important bloat.