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
- Tile Palette selected dropdown text does not update when palette is renamed
- ArgumentException thrown and reference to Template gets unset when opening UXML file after editing referenced Template in Play mode
- [iOS][WebGL] Player freezes when multiple properties of a VisualElement are changed at the same time
- Warning 'GetControlID at event ValidateCommand returns a controlID different from the one in the Layout event' is logged when undoing the deletion of an Edited Freeform 2D Light
- ShadowCaster2D breaks on certain Rotation positions when Casting Source is set to PolygonCollider2D
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