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
- Select Preset "None" icon changes after switching tabs
- [Android] Crash when using xxHash3 and targeting the ARMv7 Architecture with IL2CPP Scripting Backend
- GameObject reference in a Script Component becomes missing when unpacking a variant of another Prefab variant
- Project Settings vertical separator position is not synchronized with the mouse position when dragging it horizontally
- Crash on PhysicsDebugDraw::SelectFiltering::Update when entering play mode with Physics Debug window docked and unfocused
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