unity3d Prefabs Introduction


Example

Prefabs are an asset type that allows the storage of a complete GameObject with its components, properties, attached components and serialized property values. There are many scenarios where this is useful, including:

  • Duplicating objects in a scene
  • Sharing a common object across multiple scenes
  • Being able to modify a prefab once and having the changes apply across multiple objects/scenes
  • Creating duplicate objects with minor modifications, while having the common elements be editable from one base prefab
  • Instantiating GameObjects at runtime

There is a rule of thumb of sorts in Unity that says "everything should be Prefabs". While this is probably exaggeration, it does encourage code reuse and the building of GameObjects in a reusable way, which is both memory efficient and good design.