Search Issue Tracker
Fixed in 5.4.0
Votes
29
Found in
5.1.2f1
Issue ID
723842
Regression
Yes
GetHashCode() returns 0 for destroyed GameObjects and MonoBehaviours in Builds, but not in the Editor
To reproduce:
1. Open the attached project.
2. Open the DictionaryTests.unity scene.
3. Press Play in the Editor.
4. Observe the console output.
5. Note that the log indicates that the contents of the dictionary are identical before and after the gameobject has been destroyed.
6. Open the Build Settings dialog and ensure that DictionaryTests.unity is the only scene in the list.
7. Click Build and Play.
8. Wait for the application to start (click through the screen resolution dialog if necessary).
9. Wait for the application to quit automatically.
10. Open the player log file.
11. Observe the debug output.
12. Note that log now indicates that the hashcode of the destroyed object now changes to zero.
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
- SpeedTree does not move when using WindZone
- "Undeclared identifier 'LinearToSRGB'" error is thrown when creating a color variable with HDR color mode and assigning a Custom Render Texture target in Shader Graph
- Input System package is missing when creating a new HDRP project
- Inconsistent behaviour when interacting with different dropdown types with pointer events on parent Visual Element
- Hidden GameObjects won't re-enable when they have call "DontDestroyOnLoad" function
Michael Thomas
Nov 18, 2015 22:14
Amongst other things, this bug means that I wrote some code while testing in the editor attempting to remove all recently destroyed objects from my HashSet and it worked fine. In a standalone game build, however, it's not actually possible as far as I can tell to remove a destroyed GameObject from an existing HashSet. I've tried both RemoveWhere and looping through and using Remove() directly for the destroyed objects and both just fail to remove anything, presumably because of the hashcode mismatch.
The fact that this removal is not possible is really, really unfortunate. The fact that it's different in the editor versus standalone is HORRIBLE and now has me paranoid that any testing in the editor is entirely pointless.
umauj
Oct 08, 2015 14:39
This bug is a NIGHTMARE! The moment you cannot trust the most basic functions anymore, like when working with HashSets or Dictionaries that use the HashCode as key, everything falls apart. Please fix asap!
t0bi
Oct 08, 2015 14:17
I just committed a bugreport that basically says the same. Issue #734454