globalobjectid
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
globalobjectid [2021/02/08 06:29] – created uninomiconadmin | globalobjectid [2025/01/15 04:35] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 5: | Line 5: | ||
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. | 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. | ||
- | ===== Prefabs ===== | + | ===== Prefabs |
//All notes below only apply to running the game in Play mode in the Editor.// | //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! | + | When a scene is loaded in play mode, prefabs are unpacked |
- | Whatever process that Unity uses to unpack gameobjects(( | + | For example. You may have a prefab |
- | I've seen this mentioned | + | |
- | )) must be determinstic, | + | |
+ | '' | ||
+ | |||
+ | after unpacking (either by scene load or using PrefabUtility), | ||
+ | |||
+ | '' | ||
+ | |||
+ | Note how the zero at the end of the second GID implies the object is no longer a prefab, which is correct. I call these two GlobalObjectIds the ' | ||
+ | |||
+ | ==== Converting a Prefab Gid to an Unpacked Gid ==== | ||
+ | |||
+ | You can convert between the two using the following formula:(( | ||
+ | Source: [[https:// | ||
+ | )) | ||
+ | |||
+ | '' | ||
+ | |||
+ | ++++ Example Code| | ||
+ | |||
+ | <code csharp> | ||
+ | private static GlobalObjectId ConvertPrefabGidToUnpackedGid(GlobalObjectId id) | ||
+ | { | ||
+ | ulong fileId = (id.targetObjectId ^ id.targetPrefabId) & 0x7fffffffffffffff; | ||
+ | bool success = GlobalObjectId.TryParse( | ||
+ | $" | ||
+ | out GlobalObjectId unpackedGid); | ||
+ | Assert.IsTrue(success); | ||
+ | return unpackedGid; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ++++ | ||
+ | |||
+ | ===== Bug: Querying deleted objects ===== | ||
+ | When calling '' | ||
+ | |||
+ | For example, in this case, when passed an array of only scene objects: | ||
+ | {{ : | ||
+ | |||
+ | The function will return non-scene objects (the shader editor asset at 205). | ||
+ | {{ : | ||
+ | |||
+ | This seems to be a bug. The correct result should have been '' | ||
+ | |||
+ | I have had some luck < | ||
+ | |||
+ | Update: This is fixed in 2021.1 [[https:// | ||
globalobjectid.1612765796.txt.gz · Last modified: 2025/01/15 04:35 (external edit)