Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug NetworkPrefab has a duplicate GlobalObjectIdHash source entry value of 123

Discussion in 'Netcode for GameObjects' started by daniel_lochner, Dec 5, 2021.

  1. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    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.
     
    wlwl2 and nico_st_29 like this.
  2. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    69
    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?
     
  3. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    nico_st_29 likes this.
  4. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    69
    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.
     
  5. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    Have you encountered the issue again? I've tried removing the Library folder but still get it after a while?
     
  6. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    69
    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.
     
  7. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    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.
     
  8. luke-unity

    luke-unity

    Joined:
    Sep 30, 2020
    Posts:
    306
    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.
     
  9. IndieMarc

    IndieMarc

    Joined:
    Jan 16, 2017
    Posts:
    183
    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.
     
    wlwl2 and daniel_lochner like this.
  10. luke-unity

    luke-unity

    Joined:
    Sep 30, 2020
    Posts:
    306
    Could you report this on Github as a bug please? https://github.com/Unity-Technologi...riage,+type:bug&template=bug_report.md&title=
     
  11. IndieMarc

    IndieMarc

    Joined:
    Jan 16, 2017
    Posts:
    183
    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.


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using Unity.Netcode;
    4. using UnityEditor.SceneManagement;
    5.  
    6. namespace EditorTool
    7. {
    8.     /// <summary>
    9.     /// Fix network ID duplicate issue
    10.     /// </summary>
    11.  
    12.     public class FixNetworkID : ScriptableWizard
    13.     {
    14.         [MenuItem("Netcode/Fix Network IDs", priority = 500)]
    15.         static void ScriptableWizardMenu()
    16.         {
    17.             ScriptableWizard.DisplayWizard<FixNetworkID>("Fix Network IDs", "Fix");
    18.         }
    19.  
    20.         void OnWizardCreate()
    21.         {
    22.             NetworkObject[] nobjs = FindObjectsOfType<NetworkObject>();
    23.             foreach (NetworkObject nobj in nobjs)
    24.             {
    25.                 EditorUtility.SetDirty(nobj);
    26.             }
    27.  
    28.             EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
    29.         }
    30.  
    31.         void OnWizardUpdate()
    32.         {
    33.             helpString = "Use this tool when you receive error that there are duplicate NetworkObject ids.";
    34.         }
    35.     }
    36. }
     
  12. wlwl2

    wlwl2

    Joined:
    Jun 17, 2018
    Posts:
    29
    @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?
     
  13. wlwl2

    wlwl2

    Joined:
    Jun 17, 2018
    Posts:
    29
  14. Migaroez

    Migaroez

    Joined:
    Jun 16, 2014
    Posts:
    3
    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.
     
  15. neviovalsa

    neviovalsa

    Joined:
    Jun 24, 2019
    Posts:
    39
    What worked for me was going to the prefab, select overrides and Revert the network object component
     

    Attached Files: