Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a nested prefab?

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?

like image 328
user1306322 Avatar asked Sep 12 '13 15:09

user1306322


People also ask

What is the purpose of a prefab?

Prefabs are a special type of component that allows fully configured GameObjects to be saved in the Project for reuse. These assets can then be shared between scenes, or even other projects without having to be configured again. This is quite useful for objects that will be used many times, such as platforms.

What is the difference between a prefab and a prefab variant?

What are prefab variants ? Prefab variants are variations of a prefab that are saved as a separate prefab asset. They share their data with the original prefab asset but have a few overridden properties that differ from the original prefab. For example, you can create a variant of a character but with different colors.

What is original prefab and prefab variant?

A prefab variant keeps track of the prefab they are derived from plus changes (overrides) made to the original prefab. There are restrictions on what changes you can made. For example you can override properties, add new game objects, but not reorder children.

How can you tell if an object is a prefab?

To check if an object is part of Prefab contents in Prefab Mode, use PrefabStage. IsPartOfPrefabContents.


1 Answers

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.

like image 58
Heisenbug Avatar answered Sep 23 '22 11:09

Heisenbug