NetworkPrefab has a duplicate GlobalObjectIdHash source entry value of 123

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.

2 Likes

Hi, I’m having the exact same problem - and the GlobalObjectIdHash that is set to all NetworkObjects is also 951099334!!!

This definitely sounds like a bug. Can someone please have a look at this?

@nico_st_29 Yeah, still have this issue from time to time unfortunately… I created an issue on GitHub: NetworkPrefab has a duplicate GlobalObjectIdHash source entry value of XYZ · Issue #1499 · Unity-Technologies/com.unity.netcode.gameobjects · GitHub

1 Like

I saw that thanks. FYI I got rid of the issue (or at least I haven’t had it in a few days) by deleting the Library folder and regenerating it again.

Have you encountered the issue again? I’ve tried removing the Library folder but still get it after a while?

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.

Hope that helps.

Hey! Yes – this works for a quick fix, however, after a few runs (unsure when exactly) and also upon re-opening the project, the issue re-appears.

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.

  1. Create a script that inherits from NetworkBehaviour
  2. Create a prefab and add that prefab multiple times in the scene
  3. Attach your new script script to the prefab but do not attach NetworkObject component yet.
  4. Go in the script and add this line before the class: [RequireComponent(typeof(NetworkObject))]
  5. Try edit things in the scene and then ctrl-S or ctrl-R so that Unity adds the NetworkObject by itself.
  6. 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.

2 Likes

Could you report this on Github as a bug please? Sign in to GitHub · GitHub

Can’t believe this issue is still not fixed.

I had to come up with my own editor script to fix this everytime it happens, this should be included in the Netcode package.

Add this script to the Editor folder. and run it from the menu while your scene with the issue is opened.

using UnityEngine;
using UnityEditor;
using Unity.Netcode;
using UnityEditor.SceneManagement;

namespace EditorTool
{
    /// <summary>
    /// Fix network ID duplicate issue
    /// </summary>

    public class FixNetworkID : ScriptableWizard
    {
        [MenuItem("Netcode/Fix Network IDs", priority = 500)]
        static void ScriptableWizardMenu()
        {
            ScriptableWizard.DisplayWizard<FixNetworkID>("Fix Network IDs", "Fix");
        }

        void OnWizardCreate()
        {
            NetworkObject[] nobjs = FindObjectsOfType<NetworkObject>();
            foreach (NetworkObject nobj in nobjs)
            {
                EditorUtility.SetDirty(nobj);
            }

            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }

        void OnWizardUpdate()
        {
            helpString = "Use this tool when you receive error that there are duplicate NetworkObject ids.";
        }
    }
}

@Marc477 Do you think that this issue is happening because of changing scenes? Would there be a bug with only one scene in the whole game?

@Marc477 Nevermind, I found the answer to my own question. See the comment: NetworkPrefab has a duplicate GlobalObjectIdHash source entry value of XYZ · Issue #1499 · Unity-Technologies/com.unity.netcode.gameobjects · GitHub. Scenes do affect the ID and it happens directly too!

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.

1 Like

What worked for me was going to the prefab, select overrides and Revert the network object component