- Home /
How can I reference a prefab from within itself?
I have a GameObject with a bunch of children that is instantiated from a prefab. One of the children of that GameObject contains a reference to the prefab from which the parent was instantiated... at least initially,
When I drag the prefab from the project tab to the holding object's variable in the inspector, and then click on that variable, it appears to be linked to the prefab in the project view (the rounded rectangle appears around it).
When I select the parent object (remember, it's an instance of the prefab in question) and apply the changes, the reference in the variable, that rounded rectangle, now points to the instance in the scene in the hierarchy tab instead of the prefab in the project tab. This is not just visual, because if I try to copy the value of that variable to something that persists on scene load (which is why I'm doing this in the first place), it becomes a missing reference when the original scene is destroyed.
The nuclear option here is to put 'em all in a Resources folder and load them by name, but I'd like to avoid that. Any ideas?
Upon further testing, this also occurs when the change is made to the prefab from within the project tab. As soon as the prefab is instantiated, the reference points to the instance ins$$anonymous$$d of the prefab.
Answer by VividVisionOne · Oct 05, 2016 at 06:22 PM
Update: I have worked around this by saving the prefab to another object before it's instantiated.
I am still very much interested to hear if prefabs that reference themselves can be made to work somehow, but now it is more academic and future-oriented, rather than necessary to solve an existing problem.
Your answer
![](https://koobas.hobune.stream/wayback/20220612093934im_/https://answers.unity.com/themes/thub/images/avi.jpg)