- Home /
Suggestions for Prefabs which refer to other Prefabs
I understand that Unity3D does not support nested prefabs. While it confuses me as to why such support would not inherently be supported, I am willing to let that go and instead focus on how to achieve a similar result.
Basically what I want to do is have a Prefab A asset which has children instances of other Prefab B assets and when you drag out a Prefab A into your scene it would have all the child instances match the latest version of Prefab B. When Prefab B is updated, it would automatically update all the Prefab B children within Prefab A.
I understand that the moment you create a prefab of Prefab A all of its children are now just included as part of Prefab A and lose their link to Prefab B. But what I am looking for are suggestions on where there may be a clever way to work around this.
I don't really need the Prefab B instances to exist at all as part of the Prefab A. I just need Prefab A to hold references to them. But in order to work with Prefab A they DO need to exist while editing the scene with Prefab A in it.
One thought would be to have some way to manage the limetime of the instances of Prefab B such that they only exist while in the editor editing the scene. But when you save the scene, or save the Prefab A, the instances of Prefab B are dropped with only the references to the Prefab B asset maintained.
I guess what I am looking for is advice from those that may have a longer history of experience with this engine to suggest the best way to handle accomplishing that. I know that during OnBeforeSerialize() and OnAfterDeserialize() utilizing Unity API calls is a no no so I am wondering if such an approach is possible.
You can create a a code with one public field for the prefab, on the awake of the code instantiate the prefab, set the actual gameObject as the instance parent and destroy the code.
Yes I have a similar system already. But my problem is that I cannot make a Prefab of A without losing its link to B.
And actually that is another issue. Whenever you destroy anything within a prefab that was part of the prefab it loses its link to the original prefab as well.
Both of which is why I was thinking what I need to do is destroy the child prefabs AS the prefab is being created or saved and only load them again when it is loaded into the game or the scene.
This is the specific thing that I am looking for advice on how best to do.
Your answer
Follow this Question
Related Questions
Unity Programmatically Link Prefab 2 Answers
Prefab clone not updating 0 Answers
Prefabs won't change? 1 Answer
PrefabUtility.ReplacePrefab overrides changes 0 Answers
How to find the prefab base of a Prefab Variant through code? 1 Answer