Search Issue Tracker
Fixed in 2021.2.X
Votes
4
Found in
Issue ID
1271820
Regression
No
OnValidate called when Monobehaviour inside Prefab changes
From this forum post:
https://forum.unity.com/threads/asset-pipeline-v2-script-reimport-performance.784322/#post-6134054
It appears that OnValidate is now called every time a Monobehaviour that belongs to a Prefab changes with AssetDatabase V2.
With V1 this does not happen.
Repro with V2:
2020.2, 2020.1, 2019.4
V1 doest not call OnInvalidate()
Expected:
ADBV2 should not call OnInvalidate() for every single prefab when a script changes
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Multiple errors are thrown in the console while using perforce when moving an asset using shortcuts
- PlayerPropertiesChanged event fires before Player Properties are applied
- Opening Media Pop-out in “Before You Start” Tutorial throws “Styles” and “Styles_Dark” messages in the Console window
- Play Mode Scenario selection/highlight is too long and out of its bounds when the Play Mode Scenario window is opened after maximizing
- Asset name is not shown in the Undo History window when a sprite is modified
Resolution Note (fix version 2021.2):
At first this issue was thought to be related to the way the AssetDatabase V2 handles loaded objects.
That is not the case, as various scenarios were tested both with AssetDatabase V1 and V2.
1. Opening a Scene with Prefabs which have OnValidate in them, opening a new scene and changing some code should not trigger a call to OnValidate on the previous Scene's prefabs (does not happen on ADBV1 and ADBV2)
2. Opening a Scene with GameObjects with OnValidate in them, opening a new scene and changing some code should not trigger a call to OnValidate on the previous Scene's prefabs (does not happen on ADBV1 and ADBV2)
3. Selecting a Prefab which has OnValidate in it on the Project browser, opening a new scene and modifying some coude should not trigger a call to OnValidate (this happens on both ADBV1 and ADBV2)
The common issue between the two, is that when a Prefab is loaded into memory (either via clicking on it in the Project Browser or just loading it using AssetDatabase.LoadAssetAtPath) the object would remain in memory, and as such during a Domain Reload its OnValidate method would be called.
This is not a regression, but something that we want to fix in the near future.
As a work around until a fix arrives, switching to a new Scene and calling Resources.UnloadUnusedAssets() will clear the objects that are kept around in memory.