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
- Rigidbody2D.Slide API does not have the needed configuration when creating a 2D Top-Down character controller
- Opening reference for "Playables"component redirects to a missing page
- Sprite Renderer image is changed when switching Mask Interaction and changing Sprite to a shared Sprite
- An unsigned integer is not compared with an integer correctly in player when using IL2CPP backend
- Graphical artifacts are being rendered in Scenes that are loaded during run-time when GPU Resident Drawer is turned on
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.