Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved Something Breaks when spawning as Client

Discussion in 'Netcode for GameObjects' started by Schlucht, Mar 2, 2023.

  1. Schlucht

    Schlucht

    Joined:
    May 9, 2017
    Posts:
    12
    Hi,

    i have a testing game where i simply join and place a player prefab with

    NetworkManager.Singleton.StartHost();


    I havent worked on the projekt for a few months because of school exams, but It has worked flawlessly before without exceptions


    Now everytime i join as a client, the console gets spammed like 40 times with:

    Code (CSharp):
    1. [Netcode] Failed to create object locally. [globalObjectIdHash=2189284943]. NetworkPrefab could not be found. Is the prefab registered with NetworkManager?
    2. UnityEngine.Debug:LogError (object)
    3. Unity.Netcode.NetworkLog:LogError (string) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Logging/NetworkLog.cs:34)
    4. Unity.Netcode.NetworkSpawnManager:CreateLocalNetworkObject (Unity.Netcode.NetworkObject/SceneObject) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Spawning/NetworkSpawnManager.cs:372)
    5. Unity.Netcode.NetworkObject:AddSceneObject (Unity.Netcode.NetworkObject/SceneObject&,Unity.Netcode.FastBufferReader,Unity.Netcode.NetworkManager) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkObject.cs:1287)
    6. Unity.Netcode.CreateObjectMessage:Handle (Unity.Netcode.NetworkContext&) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/Messages/CreateObjectMessage.cs:35)
    7. Unity.Netcode.MessagingSystem:ReceiveMessage<Unity.Netcode.CreateObjectMessage> (Unity.Netcode.FastBufferReader,Unity.Netcode.NetworkContext&,Unity.Netcode.MessagingSystem) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:457)
    8. Unity.Netcode.MessagingSystem:HandleMessage (Unity.Netcode.MessageHeader&,Unity.Netcode.FastBufferReader,ulong,single,int) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:387)
    9. Unity.Netcode.MessagingSystem:ProcessIncomingMessageQueue () (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:407)
    10. Unity.Netcode.NetworkManager:OnNetworkEarlyUpdate () (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkManager.cs:1581)
    11. Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkManager.cs:1513)
    12. Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkUpdateLoop.cs:185)
    13. Unity.Netcode.NetworkUpdateLoop/NetworkEarlyUpdate/<>c:<CreateLoopSystem>b__0_0 () (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkUpdateLoop.cs:208)

    and:

    Code (CSharp):
    1. Failed to spawn NetworkObject for Hash 2189284943.
    2. UnityEngine.Debug:LogError (object)
    3. Unity.Netcode.NetworkObject:AddSceneObject (Unity.Netcode.NetworkObject/SceneObject&,Unity.Netcode.FastBufferReader,Unity.Netcode.NetworkManager) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkObject.cs:1292)
    4. Unity.Netcode.CreateObjectMessage:Handle (Unity.Netcode.NetworkContext&) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/Messages/CreateObjectMessage.cs:35)
    5. Unity.Netcode.MessagingSystem:ReceiveMessage<Unity.Netcode.CreateObjectMessage> (Unity.Netcode.FastBufferReader,Unity.Netcode.NetworkContext&,Unity.Netcode.MessagingSystem) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:457)
    6. Unity.Netcode.MessagingSystem:HandleMessage (Unity.Netcode.MessageHeader&,Unity.Netcode.FastBufferReader,ulong,single,int) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:387)
    7. Unity.Netcode.MessagingSystem:ProcessIncomingMessageQueue () (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:407)
    8. Unity.Netcode.NetworkManager:OnNetworkEarlyUpdate () (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkManager.cs:1581)
    9. Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkManager.cs:1513)
    10. Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkUpdateLoop.cs:185)
    11. Unity.Netcode.NetworkUpdateLoop/NetworkEarlyUpdate/<>c:<CreateLoopSystem>b__0_0 () (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkUpdateLoop.cs:208)

    in between the mess i also found this:

    Code (CSharp):
    1. OverflowException: Reading past the end of the buffer
    2. Unity.Netcode.NetworkObject.AddSceneObject (Unity.Netcode.NetworkObject+SceneObject& sceneObject, Unity.Netcode.FastBufferReader variableData, Unity.Netcode.NetworkManager networkManager) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkObject.cs:1305)
    3. Unity.Netcode.CreateObjectMessage.Handle (Unity.Netcode.NetworkContext& context) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/Messages/CreateObjectMessage.cs:35)
    4. Unity.Netcode.MessagingSystem.ReceiveMessage[T] (Unity.Netcode.FastBufferReader reader, Unity.Netcode.NetworkContext& context, Unity.Netcode.MessagingSystem system) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:457)
    5. Unity.Netcode.MessagingSystem.HandleMessage (Unity.Netcode.MessageHeader& header, Unity.Netcode.FastBufferReader reader, System.UInt64 senderId, System.Single timestamp, System.Int32 serializedHeaderSize) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:387)
    6. UnityEngine.Debug:LogException(Exception)
    7. Unity.Netcode.MessagingSystem:HandleMessage(MessageHeader&, FastBufferReader, UInt64, Single, Int32) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:391)
    8. Unity.Netcode.MessagingSystem:ProcessIncomingMessageQueue() (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:407)
    9. Unity.Netcode.NetworkManager:OnNetworkEarlyUpdate() (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkManager.cs:1581)
    10. Unity.Netcode.NetworkManager:NetworkUpdate(NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkManager.cs:1513)
    11. Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage(NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkUpdateLoop.cs:185)
    12. Unity.Netcode.<>c:<CreateLoopSystem>b__0_0() (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkUpdateLoop.cs:208)

    and this:

    Code (CSharp):
    1. [Netcode] NetworkPrefab hash was not found! In-Scene placed NetworkObject soft synchronization failure for Hash: 16777216!
    2. UnityEngine.Debug:LogError (object)
    3. Unity.Netcode.NetworkLog:LogError (string) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Logging/NetworkLog.cs:34)
    4. Unity.Netcode.NetworkSpawnManager:CreateLocalNetworkObject (Unity.Netcode.NetworkObject/SceneObject) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Spawning/NetworkSpawnManager.cs:391)
    5. Unity.Netcode.NetworkObject:AddSceneObject (Unity.Netcode.NetworkObject/SceneObject&,Unity.Netcode.FastBufferReader,Unity.Netcode.NetworkManager) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkObject.cs:1287)
    6. Unity.Netcode.SceneEventData:SynchronizeSceneNetworkObjects (Unity.Netcode.NetworkManager) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/SceneManagement/SceneEventData.cs:864)
    7. Unity.Netcode.NetworkSceneManager:HandleClientSceneEvent (uint) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/SceneManagement/NetworkSceneManager.cs:1781)
    8. Unity.Netcode.NetworkSceneManager:ClientLoadedSynchronization (uint) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/SceneManagement/NetworkSceneManager.cs:1747)
    9. Unity.Netcode.NetworkSceneManager:OnClientBeginSync (uint) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/SceneManagement/NetworkSceneManager.cs:1676)
    10. Unity.Netcode.NetworkSceneManager:HandleClientSceneEvent (uint) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/SceneManagement/NetworkSceneManager.cs:1774)
    11. Unity.Netcode.NetworkSceneManager:HandleSceneEvent (ulong,Unity.Netcode.FastBufferReader) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/SceneManagement/NetworkSceneManager.cs:1961)
    12. Unity.Netcode.SceneEventMessage:Handle (Unity.Netcode.NetworkContext&) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/Messages/SceneEventMessage.cs:24)
    13. Unity.Netcode.MessagingSystem:ReceiveMessage<Unity.Netcode.SceneEventMessage> (Unity.Netcode.FastBufferReader,Unity.Netcode.NetworkContext&,Unity.Netcode.MessagingSystem) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:457)
    14. Unity.Netcode.MessagingSystem:HandleMessage (Unity.Netcode.MessageHeader&,Unity.Netcode.FastBufferReader,ulong,single,int) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:387)
    15. Unity.Netcode.MessagingSystem:ProcessIncomingMessageQueue () (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:407)
    16. Unity.Netcode.NetworkManager:OnNetworkEarlyUpdate () (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkManager.cs:1581)
    17. Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkManager.cs:1513)
    18. Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkUpdateLoop.cs:185)
    19. Unity.Netcode.NetworkUpdateLoop/NetworkEarlyUpdate/<>c:<CreateLoopSystem>b__0_0 () (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkUpdateLoop.cs:208)

    and at the end there was this:

    Code (CSharp):
    1. OverflowException: Reading past the end of the buffer
    2. Unity.Netcode.ByteUnpacker.ReadUInt32Packed (Unity.Netcode.FastBufferReader reader, System.UInt32& value) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Serialization/ByteUnpacker.cs:554)
    3. Unity.Netcode.SceneEventData.SynchronizeSceneNetworkObjects (Unity.Netcode.NetworkManager networkManager) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/SceneManagement/SceneEventData.cs:858)
    4. Unity.Netcode.NetworkSceneManager.HandleClientSceneEvent (System.UInt32 sceneEventId) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/SceneManagement/NetworkSceneManager.cs:1781)
    5. Unity.Netcode.NetworkSceneManager.ClientLoadedSynchronization (System.UInt32 sceneEventId) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/SceneManagement/NetworkSceneManager.cs:1747)
    6. Unity.Netcode.NetworkSceneManager.OnClientBeginSync (System.UInt32 sceneEventId) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/SceneManagement/NetworkSceneManager.cs:1676)
    7. Unity.Netcode.NetworkSceneManager.HandleClientSceneEvent (System.UInt32 sceneEventId) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/SceneManagement/NetworkSceneManager.cs:1774)
    8. Unity.Netcode.NetworkSceneManager.HandleSceneEvent (System.UInt64 clientId, Unity.Netcode.FastBufferReader reader) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/SceneManagement/NetworkSceneManager.cs:1961)
    9. Unity.Netcode.SceneEventMessage.Handle (Unity.Netcode.NetworkContext& context) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/Messages/SceneEventMessage.cs:24)
    10. Unity.Netcode.MessagingSystem.ReceiveMessage[T] (Unity.Netcode.FastBufferReader reader, Unity.Netcode.NetworkContext& context, Unity.Netcode.MessagingSystem system) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:457)
    11. Unity.Netcode.MessagingSystem.HandleMessage (Unity.Netcode.MessageHeader& header, Unity.Netcode.FastBufferReader reader, System.UInt64 senderId, System.Single timestamp, System.Int32 serializedHeaderSize) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:387)
    12. UnityEngine.Debug:LogException(Exception)
    13. Unity.Netcode.MessagingSystem:HandleMessage(MessageHeader&, FastBufferReader, UInt64, Single, Int32) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:391)
    14. Unity.Netcode.MessagingSystem:ProcessIncomingMessageQueue() (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:407)
    15. Unity.Netcode.NetworkManager:OnNetworkEarlyUpdate() (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkManager.cs:1581)
    16. Unity.Netcode.NetworkManager:NetworkUpdate(NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkManager.cs:1513)
    17. Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage(NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkUpdateLoop.cs:185)
    18. Unity.Netcode.<>c:<CreateLoopSystem>b__0_0() (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkUpdateLoop.cs:208)

    Does anybody know what the issue is?

    Did something change or did i manage to break something?
     
  2. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hi @Schlucht , is the prefab you're trying to spawn in the list of spawnable objects of the NetworkManager? If yes, does removing and re-assigning it fix the issue?
     
    maxkcy likes this.
  3. Schlucht

    Schlucht

    Joined:
    May 9, 2017
    Posts:
    12
    Well it is set Player Prefab only. I just tried adding it to the NetworkPrefabs list, but it didn´t seem to change anything.

    Removing it as Player prefab and re-assigning also didn´t fix it.
     
  4. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    @Schlucht what Netcode For GameObject version are you using? Can you please post a screenshot of your NetworkManager's inspector? Does the player have a NetworkObject script attached to it?
     
  5. Schlucht

    Schlucht

    Joined:
    May 9, 2017
    Posts:
    12
    My Netcode version is 1.1.0. The player has the NetworkObject script on it.

    Screenshots are attached
     

    Attached Files:

  6. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Thanks, is the capsule your player? Can you updated to the latest NGO version?
     
  7. Schlucht

    Schlucht

    Joined:
    May 9, 2017
    Posts:
    12
    Yes the Capsule object is my player. The project is already older than a year and i never bothered renaming him XD

    NGO is now on Version 1.2.0, but issue still there.
     
  8. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Got it, if you change the player prefab with an empty one that only has the NetworkObject component, dos the error still appear? You can also try emptying the list of spawnable objects to see if the error pops up again, and what is causing it.
     
  9. Schlucht

    Schlucht

    Joined:
    May 9, 2017
    Posts:
    12
    K, clearing the List did not work but changing the player prefab fixed the issue
     
  10. aaforcebox

    aaforcebox

    Joined:
    Dec 13, 2016
    Posts:
    2
    I have exactly the same problem... when I connect a client running in the editor to a host running on a build, I get several of these errors:

    [Netcode] NetworkPrefab hash was not found! In-Scene placed NetworkObject soft synchronization failure for Hash: 511921737!
    [Netcode] Failed to spawn NetworkObject for Hash 511921737.

    The errors persist even replacing the player prefab with an empty network object or reseting the whole list.

    I don't get the error running the game after building though (one host and one client).
     
  11. Schlucht

    Schlucht

    Joined:
    May 9, 2017
    Posts:
    12
    Okay, yesterday I made a duplicate of my player prefab and started removing some components, I came to the conclusion that my base script of the player is causing the issue, due to after removing only that it works fine. Apparently I was wrong and may have made a change that breaks the system before I paused the project.

    Or maybe the component itself is the issue, it is hard to tell when the Error Logs don't give coherent information where it is generated.

    I will start sequentially debugging my script and see if any statements are causing the error, let's see what I can find.
     
    RikuTheFuffs likes this.
  12. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Awesome, happy to see that you manage to move forward! :D
     
  13. Schlucht

    Schlucht

    Joined:
    May 9, 2017
    Posts:
    12
    Apparently I just fixed the issue. After getting no information on where the error was caused, then i have decided today to completely removed the base player script and paste the code in a new one. It seems the issue was because of the component ID or "Local ID in File" or something. It completely works fine now.
     
  14. Schlucht

    Schlucht

    Joined:
    May 9, 2017
    Posts:
    12
    My mistake, it worked for 20 seconds and then it broke again XD
     
  15. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    @Schlucht would it be possible for you to open a bug report here? In this way, the team behind Netcode For GameObject will be able to prioritize your fix, and you'll be automatically updated about its status.
     
  16. Schlucht

    Schlucht

    Joined:
    May 9, 2017
    Posts:
    12
    Hi, yesterday I have found out what the issue was caused by. After an intense logging and debugging session, I was able to figure out that two functions in my script were causing the error, because the network objects they were generating were indeed not in the network prefabs list of the network manager. Therefore, it is finally working out.

    Is therefore still a demand for a bug report?
     
  17. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Thanks for the update! I'd say that there's no need for a bug report in this case
     
  18. firebird721

    firebird721

    Joined:
    Jun 8, 2022
    Posts:
    101
    i have similear problem but i dont have a clue -
    [Netcode] Failed to create object locally. [globalObjectIdHash=0]. NetworkPrefab could not be found. Is the prefab registered with NetworkManager?
    UnityEngine.Debug:LogError (object)
     
  19. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hi @firebird721 , did you add the prefab to the list of spawnable objects of the NetworkManager? What NGO version are you using?
     
  20. rangesstudio

    rangesstudio

    Joined:
    Nov 23, 2021
    Posts:
    6
    I suppose after you spawn it you just add it to the manager like he said? I had a similar issue except for the host has the item but the client just doesn't see it because of a similar error.
     
  21. jackward84

    jackward84

    Joined:
    Jan 26, 2017
    Posts:
    87
    Would it be possible to get the server to tell you what object is being referred to when a NO fails to spawn due to a missing/mismatched hash? It would help so much with debugging issues with network prefabs, which I run into quite often. I imagine it's especially frustrating for new people when they don't even understand what is meant by the hash mismatch and don't have much information to go on to find the problem.
     
  22. MarmionK

    MarmionK

    Joined:
    Apr 14, 2016
    Posts:
    3
    Hey everyone,

    I'm encountering the same issue, and I wanted to share my experience in hopes of finding a solution. In the past, we managed to fix this error by generating new GlobalObjectIDHashes by modifying values within the prefab itself.
    As this got tidiouse very fast we used a script to automatically do this before every build. Go through all NetworkObjects an reset the ID. This worked for a couple of month, but since a couple of days and despite trying this approach again, the error persists.

    I've thoroughly checked my code and verified that the prefab I'm attempting to instantiate on the client side is correctly registered with the NetworkManager's spawnable prefabs list.(Basically add the networkObject component and add it to the network manager, or am I forgetting something?)

    If anyone has encountered a similar situation or has any additional insights or alternative solutions, I would greatly appreciate your input.

    Here are some relevant details:

    • Unity version: 2021.3.16f
    • Netcode version: 1.1.0
    Thank you all for your contributions to this thread. I'm hoping that together we can find a resolution to this issue.

    Best regards,
     
  23. Boof

    Boof

    Joined:
    Aug 11, 2014
    Posts:
    10
    The reason why this error happened to me is because there was some NetworkObject being spawned into the scene and I forgot to include it in my NetworkPrefabsList in my NetworkManager.

    It's really unhelpful that Unity throws the GlobalObjectIdHash in the error message, because this parameter is an internal field in the NetworkObject component, so its value cannot even be read by anyone other than Unity devs. That is, unless you use Reflection.

    Here is a script I wrote to help me identify which prefab causes the error to be thrown. You can access it in Tools > Network Hash Finder. This is working in NGO v1.5.1, but might not work in future versions if the Unity devs move away from the GlobalObjectHashId solution. If a Unity dev reads this: please for the love of god make your tools easily accessible to your users so that we can debug your cryptic error messages without invoking Reflection black magic.

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using UnityEngine;
    3. using UnityEditor;
    4. using Unity.Netcode;
    5. using System.Reflection;
    6.  
    7. public class NetworkHashFinder : EditorWindow
    8. {
    9.     private string hashInput;
    10.     private NetworkObject output;
    11.  
    12.     [MenuItem("Tools/Network Hash Finder")]
    13.     public static void InitializeWindow()
    14.     {
    15.         NetworkHashFinder window = GetWindow<NetworkHashFinder>();
    16.         window.titleContent = new GUIContent("Network Hash Finder");
    17.     }
    18.  
    19.     void OnGUI()
    20.     {
    21.         bool wasEnabled = GUI.enabled;
    22.  
    23.         EditorGUILayout.BeginHorizontal();
    24.         {
    25.             hashInput = EditorGUILayout.TextField("Hash ID", hashInput);
    26.             GUI.enabled = VerifyIsInteger(hashInput);
    27.             if (GUILayout.Button("Find"))
    28.             {
    29.                 output = FindByHash(ParseInput(hashInput));
    30.                 if (output == null) Debug.Log("No GameObject found with hash ID '" + hashInput + "'");
    31.             }
    32.             GUI.enabled = wasEnabled;
    33.         }
    34.         EditorGUILayout.EndHorizontal();
    35.  
    36.         NetworkObject newOutput = EditorGUILayout.ObjectField("Object", output, typeof(NetworkObject), false) as NetworkObject;
    37.  
    38.         if (newOutput != output)
    39.         {
    40.             GUI.FocusControl(null);
    41.             hashInput = newOutput.PrefabIdHash.ToString();
    42.             output = newOutput;
    43.         }
    44.  
    45.         if (GUILayout.Button("Clear"))
    46.         {
    47.             GUI.FocusControl(null);
    48.             hashInput = "";
    49.             output = null;
    50.         }
    51.  
    52.         GUI.enabled = wasEnabled;
    53.     }
    54.  
    55.     private uint ParseInput(string input)
    56.     {
    57.         return uint.Parse(input);
    58.     }
    59.  
    60.     /// <summary>
    61.     /// Use the hashID to find the GameObject that corresponds with it
    62.     /// </summary>
    63.     private NetworkObject FindByHash(uint hashID)
    64.     {
    65.         FieldInfo info = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic);
    66.         if (info == null)
    67.         {
    68.             Debug.LogError("GlobalObjectIdHash field is null. Unity might have updated Netcode not to use this parameter anymore, in which case this tool is useless");
    69.             return null;
    70.         }
    71.         foreach (NetworkObject obj in Resources.FindObjectsOfTypeAll<NetworkObject>())
    72.         {
    73.             uint GlobalObjectIdHash = (uint)info.GetValue(obj);
    74.             if (GlobalObjectIdHash == hashID)
    75.             {
    76.                 return obj;
    77.             }
    78.         }
    79.  
    80.         return null;
    81.     }
    82.  
    83.     private bool VerifyIsInteger(string input)
    84.     {
    85.         try
    86.         {
    87.             uint.Parse(input);
    88.             return true;
    89.         }
    90.         catch (System.Exception)
    91.         {
    92.             return false;
    93.         }
    94.     }
    95. }
    96. #endif
     
  24. Hurbivore

    Hurbivore

    Joined:
    Nov 25, 2016
    Posts:
    13
    @Boof Thank you so much for this script. It saved me so much time!