Search Unity

Unable to get Local Identifier in File from Prefab

Discussion in 'Prefabs' started by fchiarandini, Jul 20, 2020.

  1. fchiarandini

    fchiarandini

    Joined:
    Mar 16, 2018
    Posts:
    5
    Hello,
    I really need to get the Local Identifier in File for prefabs dragged into the Hierarchy, but also with the new methods introduced in Unity 2019
    1. AssetDatabase.TryGetGUIDAndLocalFielIdentifier::https://docs.unity3d.com/ScriptReference/AssetDatabase.TryGetGUIDAndLocalFileIdentifier.html
    2. GlobalObjectId.GetGlobalObjectIdSlow: https://docs.unity3d.com/2019.3/Doc...nce/GlobalObjectId.GetGlobalObjectIdSlow.html
    I had no luck.

    The first one always returns me the default values for Asset Guid and Local Identifier, while the second I found out that returns always the same values of Asset Guid and Local Identifier even for different instances of the same prefab. But I need to have a unique identifier for each prefab instance, not for the original prefab asset.

    The same happens with game object instances that are not prefabs, so basically the first method never returns me any value besides the defaults, for every object in the hierarchy.

    Am I missing something? Is this a bug?

    Thanks in advance and have a nice day.

    EDIT

    Nevermind, I have only been sloppy in reading the documentation, the way to obtain the prefab Id is by calling targetPrefabId instead of targetObjectId on the GlobalObjectId object.
    It also is an interesting way to find out if the object is a prefab rather than a standard game object, because if the object is not a prefab, the Id will be 0.
     
    Last edited: Jul 21, 2020