I’ve got a bunch of prefabs with a script on them that used to have a field that’s been removed. Some of the prefab instances have modifications to that field. I thought that modifications to removed fields would automatically be removed when the prefab instance got reserialized due to something else changing, but it’s not happening.
The reason this is especially bad is that the field in question is a ScriptableObject, and that SO was stored as a part of the scene. Unity cleans out such SO’s when they’re not referenced anymore. SInce the modification to that field stays there, the SO won’t get cleared out.
In addition to all of this, we have deleted that SO’s type. This means that each of these SO’s are causing these warnings to appear in the console on startup:
The referenced script (Unknown) on this Behaviour is missing!
The referenced script on this Behaviour (Game Object '<null>') is missing!
In the scene file, this looks like this. I’ve got a prefab instance with this in it:
--- !u!1001 &1435652222
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
...
- target: {fileID: 114238998614804306, guid: ff4165164015226499e68b7cb5fdc74e,
type: 3}
propertyPath: navLocation
value:
objectReference: {fileID: 218451484}
The “navLocation” field on the script has been deleted. This is one of several fields who’s overrides are not getting removed, but this is the one causing the most problems.
Further down the file is this line:
--- !u!114 &218451484
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 35134fd8a34d47be92f33e58371449fc, type: 3}
m_Name: Krathaven 9_Location
m_EditorClassIdentifier:
35134fd8a34d47be92f33e58371449fc references a deleted script.
Things I have tried to clean this up:
-
Make changes to the prefab instance. In my experience, that causes the prefab instance to reserialize, Which usually fixes things like this, but no dice
-
Reserialize the entire scene asset, using AssetDatabase.ForceReserializeAssets. That doesn’t work either.
-
Delete the prefab instance, enter play mode, exit play mode, Undo.
This half-solves the issue, as the SO is removed from the scene file. The prefab modification is still there, but now withobjectReference: {fileID: 0}
Any advice? Is this a bug? What’s supposed to make prefab modifications that are not relevant anymore be cleared?