Hi there. Every now and then, I get this issue when trying to enter play mode:
It seems to happen with some of the prefabs in my network prefabs list. To fix it, I just revalidate the NetworkObject component (e.g., toggle one of the parameters on and off), and another GlobalObjectIdHash is generated, however it is quite annoying! Has anyone else experienced this issue?
I tried completely removing and re-adding the NetworkObject components from each of the prefabs, however, it didn’t seem to work.
Hi Daniel, sorry for the late reply. No I haven’t encountered this issue again. I use 2021.2.8f1 FYI.
When I had it before I found that for some reason the issue was sometimes occurring in one of my projects but not the other (using ParrelSync). Also, you might notice that when you recompile the code (say you change one of the options on the NetworkObject component and save or something) a new GlobalObjectIDHash gets generated.
If someone has a project where some prefabs have this issue and could upload it as a new bug to the Unity bug reporter that would be tremendously useful. We’ve been aware for this issue for a while but are unsure how it happens and don’t encounter it in our internal projects.
I had a similar issue with GlobalObjectIdHash that made all objects of the same prefab have the same ID in the scene and create a lot of bugs.
After investigation, here’s how I achieved the bug in Unity 2020.3 with the latest Netcode.
Create a script that inherits from NetworkBehaviour
Create a prefab and add that prefab multiple times in the scene
Attach your new script script to the prefab but do not attach NetworkObject component yet.
Go in the script and add this line before the class: [RequireComponent(typeof(NetworkObject))]
Try edit things in the scene and then ctrl-S or ctrl-R so that Unity adds the NetworkObject by itself.
Try to edit settings on the newly Generated NetworkObject component on the prefab
Now you will start seeing a lot of warnings and unity trying to recreate the network object over and over again will warnings appearing non-stop.
If you try to start the game from a Menu scene, then call StartHost and then load the Test scene that contains the prefabs with the NetworkManager.SceneManager.LoadScene it will reset all GlobalObjectIdHash to the same value instead of preserving the ones saved in the scene. This will throw an error because of dupplicate ID. I tried restarting unity and it was still having this issue.
The only way i managed to fix this issue is to remove [RequireComponent(typeof(NetworkObject))] and then remove the NetworkObject on the prefab, and add it manually instead of letting Unity add it automatically.
For anyone running into this in unity 2022.2.21 - netcode for gameobjects 1.4.0 (or similar)
This error also happens if your networkmanager has multiple prefab lists with multiple references to the same prefab/prefab list.