Search Issue Tracker
Fixed in 5.4.0
GetHashCode() returns 0 for destroyed GameObjects and MonoBehaviours in Builds, but not in the Editor
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.
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
- Long Prefab save times when using Unity 2022.2 and higher
- Console displays error "UnityException: Creating asset at path Assets/Scenes/ .scenetemplate failed." during scene template saving
- "Development Build" watermark is shown in non-development UWP release builds
- Console errors appear when the Inspector is set to Debug and a GameObject is selected
- A script public variable value is not used when set in the Inspector window
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.
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!
Oct 08, 2015 14:17
I just committed a bugreport that basically says the same. Issue #734454