question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NetworkObject.GlobalObjectIdHash serializes invalid values when in Prefab Mode

See original GitHub issue

Description

NetworkObject.GlobalObjectIdHash serializes to a non-unique invalid value if it is saved when the object that holds it is in Prefab Mode.

Specifically, the issue originates from var globalObjectIdString = UnityEditor.GlobalObjectId.GetGlobalObjectIdSlow(this).ToString();, in NetworkObject.GenerateGlobalObjectIdHash which will always return GlobalObjectId_V1-0-00000000000000000000000000000000-0-0 in prefab mode.

Once the object has a corrupt hash, it seems impossible to fix, and the prefab is doomed to stay corrupt without manual script tampering.

Reproduce Steps

  1. In the project view window, right click -> create -> ‘Prefab’
  2. Double click the prefab to enter ‘Prefab Mode’ in which you can edit the newly made prefab
  3. Add a ‘NetworkObject’ component and witness its readonly GlobalObjectIdHash to be 951099334 which is the hash of GlobalObjectId_V1-0-00000000000000000000000000000000-0-0.
  4. Ctrl+S to save the prefab
  5. Inspect the newly made New Prefab.prefab file in any text editor of your choice, and witness that GlobalObjectIdHash: 951099334
  6. (bonus), exit prefab mode, and select New Prefab in the project view, witness that the GlobalObjectIdHash is a non-951099334 value, despite being serialized as such.

Actual Outcome

GlobalObjectIdHash is broken and non-unique, unusable.

Expected Outcome

GlobalObjectIdHash should always be unique traceable to a unique object between different clients.

Screenshots

If applicable, add screenshots to help explain your problem.

Environment

  • OS: Windows 10
  • Unity Version: 2023.1.3f1
  • Netcode Version: 1.5.1

Issue Analytics

  • State:open
  • Created 2 months ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
NoelStephensUnitycommented, Aug 14, 2023

@Yoraiz0r Ok… finally finished figuring out what that last chunk of code was being used for and made a slight adjustment to the “type” from an imported asset (type 1) to a source asset (type 3). When editing a prefab the GlobalObjectId.GetGlobalObjectIdSlow views it as a scene object with the associated file identifier as being all 0’s since the scene used to edit the prefab is temporary. Going to run a few more tests to compare the values in-editor and in a runtime build… but I am pretty sure it looks like we want it to generate the identifier as a source asset (the prefab asset itself).

Close to putting up a PR. 👍

2reactions
NoelStephensUnitycommented, Aug 10, 2023

@Yoraiz0r & @slb1988 Thank you both for your detailed response and time spent investigating this issue. I am going to be testing both of your suggested approaches (possibly end up with a combination of both), and will post back here with the results. This is an area that has needed attention indeed, and again…wanted to thank you both for your time spent on this. (very promising suggested fixes) 🥇 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

NetworkPrefab has a duplicate GlobalObjectIdHash source ...
It seems to happen with some of the prefabs in my network prefabs list. To fix it, I just revalidate the NetworkObject component...
Read more >
Scene objects assigned same GlobalObjectIdHash value
I have a scene I load in additively that has 4 enemies pre-placed in it. They each have a NetworkObject and unique hashes....
Read more >
Class NetworkPrefabHandler | Netcode for GameObjects
Netcode.NetworkObject.GlobalObjectIdHash value of the network prefab asset being overridden. INetworkPrefabInstanceHandler, instanceHandler.
Read more >
In-Scene (Placed) NetworkObjects
An in-scene placed NetworkObject means a GameObject with a ... scene (this is required to get a proper GlobalObjectIdHash value assigned) ...
Read more >
c# - GameObject in SerializedField - OverRide - Apply All: ...
It only works for GameObject reference that are themselves a prefab living in the asset or references within one and the same prefab...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found