Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Scene objects assigned same GlobalObjectIdHash value

Discussion in 'Netcode for GameObjects' started by CasualT_Bossfight, May 26, 2022.

  1. CasualT_Bossfight

    CasualT_Bossfight

    Joined:
    Oct 26, 2016
    Posts:
    8
    I have a scene I load in additively that has 4 enemies pre-placed in it. They each have a NetworkObject and unique hashes.
    EnemyArmature, hash: 901646682
    EnemyArmature (1), hash: 851084576
    EnemyArmature (2), hash: 4170565308
    EnemyArmature (3), hash: 384220462

    However after starting the host and then loading the scene, I get the following error:

    Exception: EnemyArmature (1) tried to registered with ScenePlacedObjects which already contains the same GlobalObjectIdHash value 211529361 for EnemyArmature (3)!


    All of the enemies now have a Spawn button displayed on their NetworkObject and if I click that they all get a GlobalObjectIdHash of 211529361.

    I'm not sure what GlobalObjectIdHash is used for but I think it's pretty clear that Netcode should respect the pregenerated values and not try to regenerate them at runtime. Especially if it is using an algorithm that produces a high probability of generating duplicate values.
     
    brealin likes this.
  2. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    This happens sometimes, I’m not sure why. Removing and re-adding the NetworkObjects and restarting Unity usually fixes this for me. Alternatively, you can first try to just check/uncheck some boolean on these components and see if that does it.
     
  3. CasualT_Bossfight

    CasualT_Bossfight

    Joined:
    Oct 26, 2016
    Posts:
    8
    At first I'm like "Oh please, that'll never work." So I removed and re-added the NetworkObjects and restarted Unity and it stopped throwing those exceptions:D

    Thanks!
     
    shnagenburg likes this.
  4. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    124
    I just had this exact issue with NGO 1.2.0
    Last night everything was working but now tried to run the exact same game and got that very strange error. For some reason all the prefabs placed in the scene that were all copies of the same prefab ended up with the exact same GlobalObjectIdHash (although they each had a different NetworkObjectId)
    I removed and re-added the NetworkObject, didn't change any code, and everything works again. Very strange
    Thanks for this post!
     
  5. metainteraction

    metainteraction

    Joined:
    Jan 7, 2017
    Posts:
    1
    This issue is becoming a nightmare to manage!

    We started to see 'xxx has a duplicate GlobalObjectIdHash source entry value of: 951099334!' errors few weeks back. It is unknown how the error was triggered in the first place, it could have been caused by duplicating in-scene placed network objects, but we aren't so sure because there are scenes that have no in-scene placed objects and the error would still occur!
    Or it could have been caused by the fact that we upgraded our unity Editor from 2021 to the latest 2022 version (NGO is upgraded to 1.2.0 as a result), but we are not sure if there are clear links for it either.
    We also have suspected the new AI Navigation package might have something todo with it, because the issue occurred around the same time when we added the new AI package, but this is purely speculation. Of course, everything we tested have been speculations...

    We had gone through all the existing threads/solutions for this issue (not many info over the internet apart from one Github discussion and Unity community discussion here by the same group of developers and authors).

    Yeah we did all the removing NetworkObject thing, toggling NetworkObject flag on and off trying to force the framework to regenerate prefab globalHash again, etc. But the error would only go away for some time if we were lucky enough. And in other cases, the error messages would just stick for a while until randomly disappear if we keep trying something (recompile codes/Edit scenes/refreshing flags etc.) and so far we have not found any reliable way to suppress it.

    The final strategy we attempted was to reset our repository to the time before all these errors had occurred, and as a result we had to downgrade our Unity from 2022 to 2021.3.19. Then the error could still happen since we still upgraded NGO to 1.2.0, but at least toggling the NetworkObject flag or recompile code could meaningfully resolve the issue for sometime...

    This is definitely a bug.
     
    andreyshade likes this.
  6. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    124
    This just happened to me again.
    One more note that might be relevant to how this bug happens, the issue was in a Base prefab where I attached a NetworkObject, and then all the objects placed in the scene were prefab variants of that object.
    I have lots of objects with NetworkObject and this is the only one that caused issues, so perhaps the origin of this problem is related to prefab variants in some way.
    I did the same thing again, removed the NetworkObject from the Base prefab and added it again and now it works.
     
    saskenergy likes this.
  7. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    437
    @CodeMonkeyYT , thanks for sharing your workaround, could you please open a bug report here? It'd really help the team behind Netcode For GameObject will be able to prioritize your fix, and you'll be automatically updated about its status.
     
  8. Jozzuph

    Jozzuph

    Joined:
    Sep 12, 2019
    Posts:
    33
    I'm also having a problem with it; it worked on my old player prefab, but once I changed some things up, such as adding the sprite art, it stopped working.

    The Global Object Hash is the same, but the network object ID and Owner Client ID are different, which is what I thought mattered. I've tried removing the Network Object script, replacing it, and restarting unity, but it hasn't worked for me... The player prefabs are the same, so I shouldn't have a variant issue... any ideas?

    I have an enemy prefab that uses the same principles and works fine.
     
  9. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    I have also recently upgraded to NGO 1.2.0 (however, I cannot say if that is the problem, as I didn't have other objects in the scene with NetworkObjects before upgrading).

    However, I got this error, then I read above and remove and readded the prefab to the scene. Now it's coming on another prefab.... :(

    It only happens on the client - the host got no errors.

    It's really annoying, as I know work and then the next day, without any changes, it suddenly didn't work.

     
  10. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    Ok a minor update - I managed to fix my problem.

    So this only happens on the client and only for prefabs placed in the scene.
    I remember I read something about the order of NetworkObject was important. As I remember it said that NetworkObject had to be AFTER / lower than like NetworkTransform, NetworkRigidbody etc. so my NetworkObject was the last component on my prefabs.

    After moving NetworkObject up so it's before/higher than the other Network components, made this issue go away for me.

    If this actually fixed it or it was just because I edited the prefab I don't know, but it works right now after I changed these two prefab with the issue.

    UPDATE: Ok, after I did a minor change, unrelated to this, the issue is back. So the other is not the solution :(
     
    Last edited: Mar 9, 2023
  11. Jozzuph

    Jozzuph

    Joined:
    Sep 12, 2019
    Posts:
    33
    I'm having the same problem where it is only the client, I'll keep you updated on what I find, do the same, please!
     
  12. SamuelIH

    SamuelIH

    Joined:
    Jan 7, 2021
    Posts:
    5
    I believe it's what happens when you add a NetworkObject to a prefab that already has instances of itself in a scene:
    The
    OnValidate
    code in
    NetworkObject
    that sets the id hash never marks the id dirty in any way, so the values are never saved as prefab overrides in the scene.

    I fixed the issues I had with this quick script
    Code (CSharp):
    1. using Unity.Netcode;
    2. using UnityEngine;
    3. using UnityEditor;
    4.  
    5. public static class NetworkObjectFixer
    6. {
    7.     [MenuItem("Tools/Fix NetworkObjects in Scene")]
    8.     public static void FixNetworkObjectsInScene()
    9.     {
    10.         var networkObjects = Object.FindObjectsOfType<NetworkObject>(true);
    11.         foreach (var networkObject in networkObjects)
    12.         {
    13.             if (!networkObject.gameObject.scene.isLoaded) continue;
    14.  
    15.             var serializedObject = new SerializedObject(networkObject);
    16.             var hashField = serializedObject.FindProperty("GlobalObjectIdHash");
    17.          
    18.             // Ugly hack. Reset the hash and apply it.
    19.             // This implicitly marks the field as dirty, allowing it to be saved as an override.
    20.             hashField.uintValue = 0;
    21.             serializedObject.ApplyModifiedProperties();
    22.             // Afterwards, OnValidate will kick in and return the hash to it's real value, which will be saved now.
    23.         }
    24.     }
    25. }
    Just run it from the menu: Tools > Fix NetworkObjects in Scene and then save your scene.
     
    SchGames, Angagsu-1, liquify and 5 others like this.
  13. wirsbo64

    wirsbo64

    Joined:
    Dec 26, 2021
    Posts:
    9
    I keep getting "[Netcode] NetworkPrefab hash was not found! In-scene placed networkobject soft synchronization failure for hash: blabla" and "Failed to spawn NetworkObject for hash: bla bla".

    This hack you posted fixed all that and my NetworkObjects finally sync correctly, and I'm not getting errors. Thank you! Unity, please fix this!!!

    Be aware however that Unity didn't like to compile this script, so I had to comment out the entire script before building everything.
     
    Kapitan1991 likes this.
  14. Sadrmm

    Sadrmm

    Joined:
    Apr 11, 2020
    Posts:
    3
    I also had this issue and in my case it happened because I was creating two Singletons (both NetworkBehaviour) before generating the NetworkManager and these 2 Singletons were generated in another Scene Local that was loaded async (That scene was created before the scene with the NetworkManager).
    Once I refactored a little bit and moved the Singletons to same scene where de NetworkManager is generated the error stopped.
     
  15. RazNayr

    RazNayr

    Joined:
    Oct 17, 2019
    Posts:
    3
    Thanks for this! I was instantiating the networked object in runtime within the scene and later spawning it through clients. Removing the scene instantiations fixed my issue.
     
  16. virtual_bugLBC

    virtual_bugLBC

    Joined:
    Apr 9, 2019
    Posts:
    4
    Thanks so much, you made my day !
     
  17. gnovos

    gnovos

    Joined:
    Apr 29, 2020
    Posts:
    26
    I have/had the same problem but it had nothing to do with prefabs already placed in the scene. I have a number of objects that each spawns a new `NetworkObject`-based prefab when `OnEnable` is invoked, and if I do, then they always throw this error. Instances of these prefabs being spawned are NOT already in the scene. If I add a small delay (like 1 second) before spawning, however, this error goes away.
     
  18. fizzy6868

    fizzy6868

    Joined:
    Feb 26, 2014
    Posts:
    3
    had this same issue following your mutiplayer kitchen tut. i was like what have i done wrong after 3 hours rewatching the tutorial done some googling found this and just removed network componet from BaseCounter and done sooo frustrating when it is just a random bug
     
    SchGames likes this.
  19. Patfantasia

    Patfantasia

    Joined:
    Mar 25, 2020
    Posts:
    1
    Hi @SamuelIH !
    I think you're right, but your script doesn't work for me.

    On the Netcode docs, I've found this note dealing with in scene placed Network prefab :

    " Delete the GameObject instance in your scene (this is
    required to get a proper GlobalObjectIdHash value assigned)"
    So, I've saved world transform of my prefabs before delete them. Then, drag and drop the prefabs on the scene.

    PS: It's important to delete old prefab on the scene before importing new ones.


    Source (Netcode Doc) : scene Placed Network Prefab