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

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).

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:

  • Null target objects
  • Unknown Property Paths (which are not subject to scripted FormerlySerializedAsAttribute usage)
  • Removed components
  • Removed GameObjects
  • Changed array dimensions (e.g., materials array)

3 Ways to remove the Overrides:

  • Hierarchy Window > Scene Context Menu > Prefab > Remove
  • Hierarchy Window > Prefab/Prefabs Context Menu > Prefab > Remove
  • Inspector Window (Prefab Instance on Scene) > Overrides > Unused Overrides > Remove

Check also a Complete Optimization Guide.

2 Likes

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.

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.

8647620--1163346--2.jpeg

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.

1 Like

Please, submit a bug report to Unity, however this it doesn’t exactly look like a bug, but rather a missing functionality.

I posted here. Hoping it gets attention at some point!

1 Like

You can also duplicate it with Unity as a bug: choose Help → Report a Bug in the menu

8857042--1208212--upload_2023-3-6_23-49-28.png

This has got to be some sort of record? :hushed:

1 Like

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.

I don’t know about any API, but [Maintainer] asset works with Editor API to find the project issues.
Maybe it will help to you…