Search Issue Tracker
By Design
Votes
1
Found in
2019.2.17f1
2019.3
2020.2
Issue ID
1224308
Regression
No
NullReferenceException error is thrown to the Console when DestroyImmediate method is used
How to reproduce:
1. Open user's attached 'CustomPreviewBug.zip' project
2. Open 'SampleScene' Scene
3. Select 'Cube' GameObject in the Hierarchy
4. Enter Play Mode
Expected result: No errors thrown to the Console
Actual result: 'NullReferenceExceptionError' error is thrown to the Console
Reproducible with: 2019.3.5f1, 2020.1.0b1, 2020.2.0a2
Could not test with: 2017.4.38f1, 2018.4.19f1 because multi-object editing is not supported
Notes:
- Video of reproduction attached in Edit
- Reproducible on macOS
- If unable to reproduce the issue when entering Play Mode try to exit and enter the Play Mode for a few more times
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
- UI Toolkit 'background-size' property is not fully animatable
- Moving the Scrollbar via clicking no longer works after the first-click when page size is too small
- Elements in UI Builder Viewport are displayed incorrectly when Editor UI Scaling is set to 125%
- Prefab referencing a script is not shown in the Search window's Project tab when using "Find References In Project"
- Scroll view sensitivity remains unchanged when modifying the "--unity-metrics-single_line-height" value
Resolution Note:
Post from https://docs.unity3d.com/ScriptReference/Object.DestroyImmediate.html
This function should only be used when writing editor code since the delayed destruction will never be invoked in edit mode. In game code you should use Object.Destroy instead.
If the code should be executed in both edit- and playmode, you can use defines to change when you call which method.