Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. 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


    May 21, 2020
    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, 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.


    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


    Jan 24, 2013
    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


    May 21, 2020
    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.