This is an old revision of the document!
Every object in the Editor has a distinct GlobalObjectId. This is (effectively) the identifier Unity uses to hold references to other objects. It is guaranteed to be unique and stable between editor sessions.
GlobalObjectIds are not available at runtime. However, they are available in Play Mode in the editor. If you use these in play mode, keep in mind the notes on prefabs below.
All notes below only apply to running the game in Play mode in the Editor.
Prefabs Instances have a GID value that is different from the GID assigned when the game is run in Play Mode. When a scene is loaded in play mode, prefabs are merged (unpacked) into standard game-objects. These gameobjects have a different GID than the original prefab. However the GID of the unpacked GameObjects is *still* unique and stable!
Whatever process that Unity uses to unpack gameobjects1) must be determinstic, and generate a fileID for the new gameobject that is based on the prefab.
For example. You may have a prefab in the scene with GID:
after unpacking (either by scene load or using PrefabUtility), it will generate a GameObject with GID:
(Note how the zero at the end of the second GID implies the object is no longer a prefab, which is correct). Clearly, some aspects of the prefab are distilled down into the
4323523526593417776 fileId portion of the GID. 2)
Consequently, it is possible to get the unpacked GID of a prefab in the Editor scene by calling
PrefabUtility.UnpackPrefabInstance, querying the GID, and then calling
Undo.PerformUndo(). It's quite the hack, but seems to work just fine.