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.

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:
    624
    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.
    ----------------------------------------------------------
     
  2. FredTuna

    FredTuna

    Joined:
    Dec 28, 2016
    Posts:
    15
    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:
    624
    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:
    15
    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:
    624
    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:
    15
    makaka-org likes this.
  7. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    624