Search Issue Tracker
Won't Fix
Votes
2
Found in
2017.4
2018.4
2019.2
2019.2.4f1
2019.3
2020.1
Issue ID
1198350
Regression
No
Field Serialization in OnValidate method fails due to not being properly marked as dirty
How to reproduce:
1. Open attached project "Unity Bug With Dirty Data.zip" and scene "SampleScene"
2. In Hierarchy select "Move Right Prefabbed - Autopopulate"
3. In Inspector check that the "MoveRightAutoPopulate" -> "My RB" value is not null
4. Enter Play mode
5. Observe the red cubes and "MoveRightAutoPopulate" -> "My RB" value
Expected result: all the red cubes are moving and the "My RB" value is not null
Actual result: one of the red cubes is not moving and the "My RB" value is null
Reproducible with: 2017.4.35f1, 2018.4.13f1, 2019.2.14f1, 2019.3.0f1, 2020.1.0a14
Workaround:
In OnValidate method, force to serialize the gameobject with
UnityEditor.EditorUtility.SetDirty(this);
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
- [OpenGLES][XR] Zooming in on the camera's URP opaque texture causes "double vision" on Quest in OpenGLES3
- “[Worker0] Could not generate preview image“ error when opening macOS native plugin in the Inspector with Architecture to build for set to ARM 64-bit
- [iOS] Application.absoluteURL is empty on Awake/Start when opening via deep link with Splash Screen disabled
- Crash on MemoryManager::Deallocate when rapidly calling Addressables.LoadAssetAsync
- Crash on physx::shdfnd::atomicIncrement when adjusting values on a character controller component after entering Play mode in Prefab edit mode
Resolution Note:
Accessing other objects and marking scenes dirty during OnValidate has undefined behavior and should be avoided. OnValidate is only allowed access the object it is called on.