Hello, I’ve been working on this multiplayer game for a while now, and out of nowhere, without me starting to spawn any new network objects, I’ve started to recieve the error below when testing the game with a client player
I tested it a while ago and everything was fine, I suspect this started after I accidentally crashed Unity with an endless loop, and had to recover a scene backup. Is there any way for me to find out which object that hash refers to so I can try to fix it? Any help is incredbly welcome right now
Well, if anyone happens to have the same issue I did, managed to solve it by removing and readding every NetworkObject components in the scene, weirdly enough
[EDIT] Solution:
I had a gameobject in the scene with a network object attached(my lobby gui) which was being set to inactive. This made it all wonky and stop working. Im assuming we need the scene objects with network usage to be active?
Original question:
Any info on why this is happening??
I’ve just searched all the NetworkObjects in the scene and compared their hashes to the one in the error, none of them matched, I’m really lost on what to do right now
This started happening to me too. Readding the NetworkObjects worked initally but no longer works. The build versions are working just fine, but the editor gives this error.,Same things happening to me and readding the NetworkObjects was working but that also stopped working. The build versions are working but when I play in editor I get this error
I am getting this error in version 2022.2.9. I added a bunch of new objects to my scene, but every single one gives this error. I can’t remove and re-add all of them because that will take a lot of time, and that does not seem like a proper solution. The objects seem to work however, and I can interact with them and such, but getting 250 errors every time I start the game is super annoying. Please look into this. This has been an issue since I started making multiplayer games.
EDIT: Nevermind, the objects are NOT working correctly. They are not synced across all clients. This error breaks the entire game.
I had the same issue, caused me to scratch my head in my case it turns out it was Firewall inbound rules causing these errors in the unity editor. Hopefully this helps solve someone else’s problem.
I just faced the same issue in my project. It turns out I had two Network Objects attached to my GameManager. This was likely caused from me being prompted to add a Network Object to the Game Manager script when I was in a Scene that didn’t have it. I removed the duplicate Network Object and now it is working as expected. I hope this helps someone.
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.
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using Unity.Netcode;
using System.Reflection;
public class NetworkHashFinder : EditorWindow
{
private string hashInput;
private NetworkObject output;
[MenuItem("Tools/Network Hash Finder")]
public static void InitializeWindow()
{
NetworkHashFinder window = GetWindow<NetworkHashFinder>();
window.titleContent = new GUIContent("Network Hash Finder");
}
void OnGUI()
{
bool wasEnabled = GUI.enabled;
EditorGUILayout.BeginHorizontal();
{
hashInput = EditorGUILayout.TextField("Hash ID", hashInput);
GUI.enabled = VerifyIsInteger(hashInput);
if (GUILayout.Button("Find"))
{
output = FindByHash(ParseInput(hashInput));
if (output == null) Debug.Log("No GameObject found with hash ID '" + hashInput + "'");
}
GUI.enabled = wasEnabled;
}
EditorGUILayout.EndHorizontal();
NetworkObject newOutput = EditorGUILayout.ObjectField("Object", output, typeof(NetworkObject), false) as NetworkObject;
if (newOutput != output)
{
GUI.FocusControl(null);
hashInput = newOutput.PrefabIdHash.ToString();
output = newOutput;
}
if (GUILayout.Button("Clear"))
{
GUI.FocusControl(null);
hashInput = "";
output = null;
}
GUI.enabled = wasEnabled;
}
private uint ParseInput(string input)
{
return uint.Parse(input);
}
/// <summary>
/// Use the hashID to find the GameObject that corresponds with it
/// </summary>
private NetworkObject FindByHash(uint hashID)
{
FieldInfo info = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic);
if (info == null)
{
Debug.LogError("GlobalObjectIdHash field is null. Unity might have updated Netcode not to use this parameter anymore, in which case this tool is useless");
return null;
}
foreach (NetworkObject obj in Resources.FindObjectsOfTypeAll<NetworkObject>())
{
uint GlobalObjectIdHash = (uint)info.GetValue(obj);
if (GlobalObjectIdHash == hashID)
{
return obj;
}
}
return null;
}
private bool VerifyIsInteger(string input)
{
try
{
uint.Parse(input);
return true;
}
catch (System.Exception)
{
return false;
}
}
}
#endif
Sorry about posting in an old topic, but I am having the same issue and I figured a few things about this. First, for me, it happened in GameObjects containing NetworkObject component that were placed in the scene. All Hashes that resulted in error, were belonging to those GameObjects. Although the original prefab duplicated to populate the scene was present in the NetworkManager script, the Hash from the original prefab differed from the hashes placed in the scene. I guess everytime I duplicate the prefab to create my scene, a new hash is generated.
On the other hand, when I spawn the object in the scene, the spawned object has the same hash of the original prefab, which matches the one in the NetworkManager. So, I figured out a way to easily spawn the NetworkObjects in the scene, and avoid breaking it up. You just place the following script in a GameObject, and place it in your scene.
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
public class NetworkSpawner : MonoBehaviour
{
[SerializeField] private List<SpawnerItem> spawnerList;
private void Awake()
{
SpawnScenarioEvent.SetTargetEvent += Spawn;
}
public void Spawn()
{
if (NetworkManager.Singleton.IsServer) {
foreach (var item in spawnerList) {
var instance = Instantiate(item.prefab, item.transform.position, item.transform.rotation);
instance.GetComponent<NetworkObject>()?.Spawn();
}
}
}
}
public static class SpawnScenarioEvent
{
public delegate void SpawnEvent();
public static event SpawnEvent SetTargetEvent;
public static void TriggerSpawnEvent()
{
SetTargetEvent?.Invoke();
}
}
[System.Serializable]
public struct SpawnerItem
{
public Transform transform;
public GameObject prefab;
}
Then you go on the inspector and configure the prefabs to be must spawned and their respective positions (empty transforms in the scene). You can have one object to spawn of prefabs, or you can use as many as you wish to keep your scene organized.
Finally, after starting the host or server, you trigger the event to spawn all prefabs in their respective locations as in the example below:
For anyone hitting this using the Default Player Prefab (or possibly without it) and unity’s Multiplayer Play Mode I fixed it by opening the Multiplayer Play Mode window and deactivating and reactivating the other players. Somehow their editors got out of sync when I was changing the prefabs and they don’t get resynced until you turn them off and on. Hope that helps!
For anyone reading this who has a persistent problem with “ghost prefabs” appearing that are not in the network prefab list and none of these solutions seem to work. I had this problem.
It turned out that I had made a mistake in serializing/deserializing one of the network variables. Nothing complained but I got persistent and repeatable error messages as above. It looks like, somehow and even though I am sure that Unity claim it can not happen, the serializer was writing or reading out side of the buffer!
Fixed the Network Variable and the problem seems to have gone away.