prefab-object.rst 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. .. include:: ../_header.rst
  2. The prefab object
  3. ~~~~~~~~~~~~~~~~~
  4. The `prefab object <prefab-object.html>`_ is the object at the top of the prefab_ file. You can add many objects to the scene, but only the one at the top will be considered as the real prefab_, the other objects will be ignored.
  5. We did it this way for simplicity, but it also allows us to create different versions of the `prefab object`_ and move them to the top of the list in case we want to promote a different object as the `prefab object`_.
  6. Look in the next image, it shows the **Dragon** prefab. There are three objects in the file, but only the **green dragon** object will be used as the `prefab object`_ of the **Dragon** prefab_. Also, look the others, non-top objects are rendered transparent in the |OutlineView|_:
  7. .. image:: ../images/scene-editor-prefab-object-1-06272020.webp
  8. :alt: Prefab object
  9. If later you decided to use a different dragon for your prefab_, then you can move it to the top of the scene and that's all:
  10. .. image:: ../images/scene-editor-prefab-object-2-06272020.webp
  11. :alt: Another prefab object
  12. Another characteristic of the `prefab object`_ is that you cannot edit its `Variable properties <variable-properties.html>`_, because, in the generated code, it is not referenced as a variable, it is referenced as ``this``.
  13. The `prefab object`_ could be any object of any type (an `image <image-object.html>`_, a `text <text-object.html>`_, a `container <container-object.html>`_, whatever type supported by the |SceneEditor|_), even, it could be a |PrefabInstance|_. When the `prefab object`_ is a |PrefabInstance|_ (of the prefab_ **SomePrefab**) then we say it is a |PrefabVariant|_ of the **SomePrefab** prefab_.
  14. Automatic Container creation
  15. ````````````````````````````
  16. In many cases, your prefab_ will be a single object, like an image. In other cases, you do group several objects in a `Container <container-object.html>`_.
  17. To simplify the workflow of creating a prefab_, the |SceneEditor|_ will follow these rules:
  18. 1. If you add an object in an empty prefab_ scene, the new object will be the `prefab object`_.
  19. 2. If you create an object, but the prefab_ scene already contains a `prefab object`_, then:
  20. 2.1. If the `prefab object`_ is a `Container`_ , the new object is added to it.
  21. 2.2. If the `prefab object`_ is not a `Container`_, then a new `Container`_ will be created to group the old `prefab object`_ and the new object. Finally, the newly created `container`_ will be the new `prefab object`_.
  22. In a few words, following these rules, the |SceneEditor|_ automatically group the objects in a `Container`_, if needed.