Flax Facts #20 – Nested Prefabs

Flax Facts

Flax Facts #20 – Nested Prefabs

Feature Preview: Prefabs

In the latest Flax Alpha update version 0.2.6165 we’ve shipped very important feature: Nested Prefabs. Prefabs are assets used to build archetypes of actors and scripts to be reused when building game levels or by the gameplay logic. Creating procedural levels is a very good example where using prefabs can help with rapid prototyping and achieving desired gameplay. The prefab acts like a template or an archetype which you can spawn in the scene. Any edits made to a prefab asset are immediately reflected in all instances produced from it but you can also override components and settings for each instance individually. This helps with creating advanced gameplay content.
Also, Flax supports nesting prefabs inside the prefabs out of the box!

To learn more about prefabs see the related documentation here.

Nested Prefabs

How to use prefabs in Flax?

The easiest option to create a new prefab asset is by using the existing actors as an archetype. To do it simply select the actor on a scene that you want to turn into a prefab and drag it into the Content Window. Specify its name and hit enter to confirm.

New Prefab

Then double-click and edit your new asset. Prefab Editor window is the main tool to preview and edit prefab assets. Saving modified prefab asset synchronizes the changes with the existing instances of the prefab in the scene including all prefabs using this prefab as a nested prefab. Prefab Editor works like Scene Editor combined with Scene Tree Window and Properties Window that are inbuilt in Flax Editor. Except Prefab Editor shows and edits only the given prefab asset.

Prefab Editor Window supports full undo so any of your actions can be reverted. You can also open and edit more than one prefab at once.

Prefab Editor

To spawn the prefab into your game level you can simply drag the asset from the Content window into the Scene Editor window or Scene Tree window. Spawned object(s) will be linked to the prefab asset.

Spawn Prefab

Another way to create a new prefab object instance is by using a spawning method from the Flax C# API. You can spawn prefab to the scene and specify its transform or a parent actor. The following script spawns a prefab.

PrefabManager.SpawnPrefab(myPrefab, new Vector3(0, 10, 0));

What’s next?

Having ready to use Prefabs System is defenetly great for the games development with Flax. Now, we will continue improving the engine and start working on more exciting features (terrain, particles, plugins…).

Anyway, I hope you liked this feature.
Bye! 😀


Wojciech Figat

Lead Developer

2 COMMENTS
  • Rasmus
    Reply

    When are the beta coming out`? Can’t wait to try out the engine

    1. Wojciech Figat
      Reply

      We plan Open Beta early next year.

Leave a Reply

Your email address will not be published. Required fields are marked *