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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Unity 2022.2 introduces a new optimization technique: Removing Unused Overrides in Prefab Instances

Discussion in 'Community Learning & Teaching' started by makaka-org, Nov 24, 2022.

  1. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    878
    Unity 2022.2 introduces a new optimization technique: Removing Unused Overrides in Prefab Instances.

    You can clear unused Overrides stored in a scene but never accessed (because the property has been removed from a script).

    remove-unused-overrides-in-prefab-unity.jpg

    In the worst case, such properties might reference assets that are then pulled into the final build, taking up space on the storage device and in memory – but never used.

    Overrides are now flagged as unused for:
    1. Null target objects
    2. Unknown Property Paths (which are not subject to scripted FormerlySerializedAsAttribute usage)
    3. Removed components
    4. Removed GameObjects
    5. Changed array dimensions (e.g., materials array)
    3 Ways to remove the Overrides:
    1. Hierarchy Window > Scene Context Menu > Prefab > Remove
    2. Hierarchy Window > Prefab/Prefabs Context Menu > Prefab > Remove
    3. Inspector Window (Prefab Instance on Scene) > Overrides > Unused Overrides > Remove
    Check also a Complete Optimization Guide.
    ----------------------------------------------------------
     
    Stardog likes this.
  2. FredTuna

    FredTuna

    Joined:
    Dec 28, 2016
    Posts:
    16
    I can't find a way to do this for a bunch of prefab variants at once. I have a lot of prefab variants which have tons of unused overrides that are bloating the asset file. There should be a way to remove all unused overrides on all those prefab variants without having to open each one of them and manually click on the remove unused overrides button. Even from script, PrefabUtility doesn't expose any method for manipulating unused overrides as they are all internal.
     
  3. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    878
    When selecting one or more Prefab instances in the Hierarchy and opening the Overrides drop-down, the Editor now shows whether there are unused Overrides. You can then remove them from the scene using the new Unused Overrides drop-down.

    2.jpeg
     
  4. FredTuna

    FredTuna

    Joined:
    Dec 28, 2016
    Posts:
    16
    Yeah that doesn't work for prefab variant assets. Prefab variants are like prefab instances but I have to open each prefab variant individually to remove unused overrides. I wish I could remove unused overrides on prefab variant assets by just selecting them in the project instead of having to open them. That way I could select many of them and remove unused overrides in one click.
     
    makaka-org likes this.
  5. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    878
    Please, submit a bug report to Unity, however this it doesn't exactly look like a bug, but rather a missing functionality.
     
  6. FredTuna

    FredTuna

    Joined:
    Dec 28, 2016
    Posts:
    16
    makaka-org likes this.
  7. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    878
  8. necroEternal

    necroEternal

    Joined:
    May 5, 2018
    Posts:
    1
    upload_2023-3-6_23-49-28.png

    This has got to be some sort of record? :eek:
     
    makaka-org likes this.
  9. okoUser1

    okoUser1

    Joined:
    Jan 9, 2020
    Posts:
    7
    Is there something in the Unity API that we can use to remove unused references as a part of our build pipeline via script? I'd love to do this before building.
     
  10. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    878
    I don't know about any API, but Maintainer works with Editor API to find the project issues.
    Maybe it will help to you...