Prefabs
Sometimes you need to reuse entities including their components and their descendants. Instead of use copy and paste or entity duplication for doing this, that will create maintenance problems, you can use the concept of prefab. A prefab is a type of asset which helps developers with this basic function: reusing.
Creating a prefab
To create a prefab, first you need to build your entities hierarchy and assign components. For example, we can create an entity with a teapot and a plane, and a Spinner component to the top of this hierarchy.
To create a prefab, right click on the top-most entity that you wan to include in it, and select Create prefab option.
This will create a new asset with weprefab extension the same folder that you have selected in Project Explorer panel. If you created prefab in the wrong folder, don't worry as they are like any other Evergine asset, you can move it wherever you want.
If you save changes and reload the scene, you will realize that entities that were part of created prefab, are marked now with a "(Prefab)" suffix. Using prefab creation option is not reversible once you save the scene. You can also drag and drop asset element from Asset Details panel to your scene, to create new prefab instances.
Prefabs edition
If you change values on those entities, this will no affect to new and existing prefab instances. In future releases, we plan to provide an specific prefabs editor. For now, a good option is to create your prefab in a separated scene. At the time of using Create prefab option, a new prefab file will be created, but do not save the scene. Doing this, you could modify your entities in the future. Just replace previous prefab file version with the new one.
We don't officially support prefab nesting. This is, create a separated scene for your prefab, and use another prefab in that scene.
Prefab instantiation
To create a prefab instance programmatically, you can use following code snippet:
var prefab = this.assetsService.Load<Prefab>(EvergineContent.Scenes.Entity_weprefab);
var entity = prefab.Instantiate();