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
- Tile Palette: "Create New Tilemap" dropdown area is displayed in several colors
- Input.mousePosition stops syncing to touch input when using "DownloadHandlerTexture" in WebGL build
- UI Builder canvas doesn't update element styling accordingly when changing Active Theme for some Editor Authoring elements
- Selector Value buttons are not aligned with parameters in UI Builder
- Dragger elements from Slider controls doesn't scale and stay outside minimized Canvas window in UI Builder Viewport in UI Builder
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.