Search Unity

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:
    452
    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:
    452
  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.