Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Nested Prefabs fileID reference does not exist

Discussion in 'Prefabs' started by wouter_v, Nov 12, 2019.

  1. wouter_v

    wouter_v

    Joined:
    Jan 27, 2018
    Posts:
    6
    I'm making a migration tool for scene's and am now including prefabs and nested prefabs. To migrate the data I need to know what type of class/MonoBehaviour the document is (can be found with the original fileID and guid). For a normal prefab (without the nesting) this can be done by going in the scene file to the
    PrefabInstance -> M_Modification -> M_Modifications -> Target -> fileID 
    This fileID then is the flag of the document in the prefab file i'm working with (a quick ctrl + f shows what script it is).

    But this does not seem to work when prefabs are nested. It then has a fileID that does not exist anywhere else in the project (that i can find). It seems just randomly generated like the normal prefab and a reference to something i can't find as it changes when the script is re-added.

    I've exported it to a package and unzipped it but there isn't any special mapping other then the normal files. But the import in a new project works fine, which should mean that the fileID is some kind of a reference as the reference stays intact. (I've added the package to the post)

    Any information about the nested prefab fileID would be appreciated.
     

    Attached Files:

    Last edited: Nov 12, 2019
  2. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    wouter_v likes this.
  3. wouter_v

    wouter_v

    Joined:
    Jan 27, 2018
    Posts:
    6
    Thanks, this was what I needed! I'll try it soon and report back if I have a sample for others.
     
  4. wouter_v

    wouter_v

    Joined:
    Jan 27, 2018
    Posts:
    6
    Is there any way to calculate the
    FileID_of_nested_PrefabInstance
    with the .prefab and .prefab.meta files? Currently i would have to calculate the fileID for every prefab and every yamldocument in that prefab which seems like a workaround.
     
  5. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
  6. wouter_v

    wouter_v

    Joined:
    Jan 27, 2018
    Posts:
    6
    Unfortunately I don't think that the AssetDatabase will work as I just have the files and not the loaded in Unity project.

    For context, I'm making a migration tool to move scenes and now prefabs from one project to another. But that also means that i don't have access to the AssetDatabase in the original project as this code is executed from the new project.

    Now to clarify the problem:

    I have a scene file called Example.unity in this scene there is a prefab(Prefab.prefab) and in this prefab there is a prefab nested (PrefabNested.prefab). Now I look through the scene and find the PrefabInstance.m_SourcePrefab.guid element and move to that prefab (Prefab.prefab) to also migrate that prefab.

    Now in this prefab (Prefab.prefab) I find another PrefabInstance but this time without the guid so i had no idea which prefab this references. For the tool I'm writing I need to change the PrefabInstance.m_Modification.m_Modifications[].propertyPath as this field should be migrated. But to know what i need to change it to I need to know which script it actually is which I'm working on. For this I need to look in the nested prefab(PrefabNested.prefab). But the fileID in the Prefab.prefab doesn't match the fileID in the nested prefab (NestedPrefab.prefab). So first I need find which prefab it is, the script is on.

    With the current solution i would have to loop through all prefabs in the project and find all scripts in those prefabs and run the following on it :

    (FileID_of_nested_PrefabInstance ^ FileID_of_object_in_nested_Prefab) & 0x7fffffffffffffff;


    This would then result in all the fileIDs being calculated and I would then be able to find the script and prefab that I'm looking for.

    This is definitely a solution that could work and I think this is currently the way to go, but it would be amazing if I could in some way calculate a fileID that would point me to the correct prefab from within the Prefab.prefab. This would make the processing a lot easier.

    But if these fileIDs are generated and I won't be able to read them then I'll just have to parse all prefabs.
     
  7. Ensutee

    Ensutee

    Joined:
    Apr 11, 2013
    Posts:
    10
    For future reference (because this took me some tinkering to figure out) if a scene has a modification for double nested prefab the fileId in the scene file 'modification' is calculated by adding each layer of prefab instance to the xor '^' operation.

    scene (overwrites PrefabC)
    - PrefabA
    -- PrefabB
    --- PrefabC


    the fileId for the modification listed in the scene file would be
    (<PrefabA fileId in scene file> ^ <PrefabB fileId in PrefabA file> ^ <PrefabC fileId in PrefabB file>) & 0x7fffffffffffffff
     
  8. Zalo

    Zalo

    Joined:
    Sep 20, 2012
    Posts:
    8
    I was thinking... isn't it posible to have fileid conflicts if you have several nested prefabs? Imagine this hierarchy
    Code (CSharp):
    1.  
    2. - Prefab A
    3.    - Prefab B
    4.       - child 0
    5.       - child 1
    6.       - ...
    7.    - Prefab C
    8.       - child 0
    9.       - child 1
    10.       - ...
    11.  
    I know there is a small chance but there is still a small posibility that any children of B and C end up having the same fileid when being referenced from prefab A since you can edit any of those prefabs separately (you can open PrefabB and start generating GameObjects)

    Actually I was able to create this conflict manually (by changing the ids on the prefabs from a text editor) and I ended up with a corrupted prefab

    Code (CSharp):
    1.  
    2. Duplicate identifier -1764472761. File: "Assets/TestPrefab.prefab".
    3. UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
    4.  
    5. Error loading the file 'Assets/TestPrefab.prefab'. File has multiple objects with same identifiers. Probably caused by a merge.
    6. UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
    7.  
    I think it's posible that this happens.. or am I missing something here?
     
    Last edited: Nov 12, 2023