.. include:: ../_header.rst Prefabs ------- .. toctree:: prefab-new-file prefab-object prefab-user-properties prefab-create-instance prefab-display-properties prefab-code prefab-set-properties prefab-variant prefab-nested prefab-instance-children prefab-black-box A prefab_ is a key concept in the |SceneEditor|_. It allows for creating reusable, customized objects. It borrows some concepts from the |Unity|_ prefabs. In a game level, there are many objects with a common behavior and appearance. For example, several enemies look the same and act the same. Or there are the "coins" that have the same animation and play the same sound when are taken. Or the player object is the same in all the levels. All these objects are perfect candidates to be created as |PrefabInstances|_. You can see a prefab_ as the template of multiple objects. Or you can see a prefab_ as a class, so you can create multiple instances of that class and place them in a scene. In the end, a prefab_ is just a class. If you look into the code generated by the |SceneCompiler|_, a prefab_ scene is compiled into a class that extends a Phaser_ built-in type, a |ScriptNode|_, or another prefab_ class. And the |PrefabInstances|_ are just instances of the generated class. At the same time, you can customize |PrefabInstances|_ by changing the value of its properties. If a property of the prefab_ (the class) is modified, this modification is applied to all the |PrefabInstances|_, if it is not overriding in the |PrefabInstance|_. A very precise way to know how prefabs_ work, is to look into the code generated by the |SceneCompiler|_. You will realize that it is just about Object Oriented Programming concepts like class, inheritance, properties, composition, and instances.