# Nested Prefabs fileID reference does not exist

**URL:** <https://discussions.unity.com/t/nested-prefabs-fileid-reference-does-not-exist/765306>\
**Category:** Asset & Content Management\
**Tags:** Prefabs\
**Created:** [November 12, 2019, 4:44pm UTC](https://discussions.unity.com/t/nested-prefabs-fileid-reference-does-not-exist/765306 "2019-11-12T16:44:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![wouter\_v](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/wouter_v/32/469605_2.png) [@wouter\_v](https://discussions.unity.com/u/wouter_v)\
**Post date:** [November 12, 2019, 4:44pm UTC](https://discussions.unity.com/t/nested-prefabs-fileid-reference-does-not-exist/765306/1 "2019-11-12T16:44:50Z")

</div>

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.

[5167172–512687–nested prefab test.unitypackage](https://discussions.unity.com/uploads/short-url/5Yrv589cCsd9EYBa4AiTcQb3Wsa.unitypacka) (7.07 KB)

---

<div class="post-metadata">

**Author:** ![SteenLund](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/steenlund/32/576994_2.png) [@SteenLund](https://discussions.unity.com/u/SteenLund)\
**Post date:** [November 13, 2019, 7:49am UTC](https://discussions.unity.com/t/nested-prefabs-fileid-reference-does-not-exist/765306/2 "2019-11-13T07:49:14Z")

</div>

fileID for nested prefabs and also variants are generated based on the prefab instance and the corresponding object

(FileID\_of\_nested\_PrefabInstance ^ FileID\_of\_object\_in\_nested\_Prefab) & 0x7fffffffffffffff;

> [@How is fileID generated for m\_CorrespondingSourceObject ?](https://discussions.unity.com/t/754235/2):
>
> @pushxtonotdie For variants the FileID is the (FileID\_of\_PrefabInstance\_in\_variant ^ FileID\_of\_object\_in\_base\_Prefab) & 0x7fffffffffffffff;

---

<div class="post-metadata">

**Author:** ![wouter\_v](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/wouter_v/32/469605_2.png) [@wouter\_v](https://discussions.unity.com/u/wouter_v)\
**Post date:** [November 13, 2019, 10:26am UTC](https://discussions.unity.com/t/nested-prefabs-fileid-reference-does-not-exist/765306/3 "2019-11-13T10:26:31Z")

</div>

> [@SteenLund](#):
>
> fileID for nested prefabs and also variants are generated based on the prefab instance and the corresponding object
> 
> (FileID\_of\_nested\_PrefabInstance ^ FileID\_of\_object\_in\_nested\_Prefab) & 0x7fffffffffffffff;
> 
> [https://discussions.unity.com/t/754235/2](https://discussions.unity.com/t/754235/2)

Thanks, this was what I needed! I’ll try it soon and report back if I have a sample for others.

---

<div class="post-metadata">

**Author:** ![wouter\_v](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/wouter_v/32/469605_2.png) [@wouter\_v](https://discussions.unity.com/u/wouter_v)\
**Post date:** [November 15, 2019, 9:02am UTC](https://discussions.unity.com/t/nested-prefabs-fileid-reference-does-not-exist/765306/4 "2019-11-15T09:02:52Z")

</div>

> [@SteenLund](#):
>
> fileID for nested prefabs and also variants are generated based on the prefab instance and the corresponding object
> 
> (FileID\_of\_nested\_PrefabInstance ^ FileID\_of\_object\_in\_nested\_Prefab) & 0x7fffffffffffffff;
> 
> [https://discussions.unity.com/t/754235/2](https://discussions.unity.com/t/754235/2)

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.

---

<div class="post-metadata">

**Author:** ![SteenLund](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/steenlund/32/576994_2.png) [@SteenLund](https://discussions.unity.com/u/SteenLund)\
**Post date:** [November 15, 2019, 2:11pm UTC](https://discussions.unity.com/t/nested-prefabs-fileid-reference-does-not-exist/765306/5 "2019-11-15T14:11:54Z")

</div>

I am not sure what you are asking for?

Lets say you have Prefab B, that nests prefab A. In that case, the file called B.prefab will contain a PrefabInstance object. This object will have a FileID which is randomly generated when prefab B is created and it can’t be calculated.

Getting that FileID can be done with [Unity - Scripting API: AssetDatabase.TryGetGUIDAndLocalFileIdentifier](https://docs.unity3d.com/ScriptReference/AssetDatabase.TryGetGUIDAndLocalFileIdentifier.html)

---

<div class="post-metadata">

**Author:** ![wouter\_v](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/wouter_v/32/469605_2.png) [@wouter\_v](https://discussions.unity.com/u/wouter_v)\
**Post date:** [November 15, 2019, 4:03pm UTC](https://discussions.unity.com/t/nested-prefabs-fileid-reference-does-not-exist/765306/6 "2019-11-15T16:03:33Z")

</div>

> [@SteenLund](#):
>
> I am not sure what you are asking for?
> 
> Lets say you have Prefab B, that nests prefab A. In that case, the file called B.prefab will contain a PrefabInstance object. This object will have a FileID which is randomly generated when prefab B is created and it can’t be calculated.
> 
> Getting that FileID can be done with [https://docs.unity3d.com/ScriptReference/AssetDatabase.TryGetGUIDAndLocalFileIdentifier.html](https://docs.unity3d.com/ScriptReference/AssetDatabase.TryGetGUIDAndLocalFileIdentifier.html)

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](https://github.com/WouterVanmulken/Unity-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[&nbsp;].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.

---

<div class="post-metadata">

**Author:** ![Ensutee](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@Ensutee](https://discussions.unity.com/u/Ensutee)\
**Post date:** [November 18, 2022, 9:59pm UTC](https://discussions.unity.com/t/nested-prefabs-fileid-reference-does-not-exist/765306/7 "2022-11-18T21:59:26Z")

</div>

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
- 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```
````

---

<div class="post-metadata">

**Author:** ![Zalo](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/zalo/32/349547_2.png) [@Zalo](https://discussions.unity.com/u/Zalo)\
**Post date:** [November 12, 2023, 9:13am UTC](https://discussions.unity.com/t/nested-prefabs-fileid-reference-does-not-exist/765306/8 "2023-11-12T09:13:21Z")

</div>

> [@SteenLund](#):
>
> fileID for nested prefabs and also variants are generated based on the prefab instance and the corresponding object
> 
> (FileID\_of\_nested\_PrefabInstance ^ FileID\_of\_object\_in\_nested\_Prefab) & 0x7fffffffffffffff;
> 
> [https://discussions.unity.com/t/754235/2](https://discussions.unity.com/t/754235/2)

I was thinking… isn’t it posible to have fileid conflicts if you have several nested prefabs? Imagine this hierarchy

```csharp
- Prefab A
   - Prefab B
      - child 0
      - child 1
      - ...
   - Prefab C
      - child 0
      - child 1
      - ...

```

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

```csharp
Duplicate identifier -1764472761. File: "Assets/TestPrefab.prefab".
UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()

Error loading the file 'Assets/TestPrefab.prefab'. File has multiple objects with same identifiers. Probably caused by a merge.
UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()

```

I think it’s posible that this happens… or am I missing something here?

---

<div class="post-metadata">

**Author:** ![ph3rin](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/ph3rin/32/315250_2.png) [@ph3rin](https://discussions.unity.com/u/ph3rin)\
**Post date:** [August 1, 2026, 4:28am UTC](https://discussions.unity.com/t/nested-prefabs-fileid-reference-does-not-exist/765306/9 "2026-08-01T04:28:20Z")

</div>

I guess that’s why they made file IDs 64-bit. Just to make the chance that this happens astronomically small.
