I'm getting links to this post today all over the social media. It seems some people made a useful piece of code to work with "nested prefabs". This thing is somehow related to 3D game development, and specifically Unity3D, which evidently doesn't support(?) them out-of-the-box.

But what is a nested prefab?

有帮助吗?

解决方案

A prefab is basically a prototype of a GameObject (potentially a hierarchy of GameObjects), with the attached Components and their relatives sets of serialized properties.

When you put a instance of a Prefab into the scene hierarchy, we can say that you have a instance of a prefab in the scene (or a GameObject linked to a prefab). This is quite useful because if you modify the prefab itself, all the modifications are propagated to the linked prefabs in all the scenes.

Now, for what concern your specific question: Unity doesn't support nested prefabs natively. Prefab are atomic entities in such a way that you cannot specify hierarchical relations between them.

For example if you have 2 prefab A and B, and you create a third prefab C which has A and B as children, Unity will consider C as a completely separate prefab. So if you modify A or B the modifications won't be actually propagated to the prefab C.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top