New prefab workflow in 2018.3

Unity 2018.3 is around the corner, and with it comes a new Prefab workflow. This workflow will make your lives much easier, when it comes to edit and manage prefabs. Let’s take a look at all its new features and how they will help you to boost your productivity. Getting started To follow this tutorial, […] By Enrique Moreno Tent.

Leave a rating/review
Save for later
Share

Contents

Hide contents

New prefab workflow in 2018.3

10 mins

Unity 2018.3 is around the corner, and with it comes a new Prefab workflow. This workflow will make your lives much easier, when it comes to edit and manage prefabs. Let’s take a look at all its new features and how they will help you to boost your productivity.

To follow this tutorial, you will need to use version Unity 2018.3. At the time of writing this article, the only way to get it is to download the beta version. But that will be more than enough to experiment with the features here described. You can easily download the beat using the Unity Hub.

A prefab is a game object that has been already set up. They are used to create as many copies of themselves as it is needed, when they are required multiple times during a scene.

Prefabs can have many kinds of uses, when it comes to game development. A programmer might use them to create waves of enemies of the same kind. Another example could be to create many instance of different kinds of items and pick-ups. It is hard to imagine a game that can work without prefabs.

After loading a new scene there doesn’t seem to be anything new, except for a small detail. In the Hierarchy panel there are see gray cube icons next to the name of the game objects in the scene.

While this is nicer to look at, there is much more behind it. To see it, first you want to create a prefab.

Creating a new prefab hasn’t changed. Create a new game object in the scene, and drag it to a project folder. After doing this, you will notice another difference. Now the cube next to instance of the prefab is blue. Before 2018.3, the only way to differentiate these cases was looking at the text color of that object’s name. If it is blue, it is an instance of a prefab. This is still true, but the addition of those icons next to the name makes it much easier to distinguish in a glance.

Prefab instances are not always used with the default values of its components. Sometimes you will want to change some values, depending on the context. For instance, you might want to change its scale and make it smaller. Before 2018.3, the editor marked these differences with a thicker font, which was quite hard to see. While this still exists, now there are new ways to check and edit your modifications.

After changing a value in the inspector, you will see that a blue line has appeared right next to the attribute. This will happen every time you override any value of your instance. There are only 2 exceptions to this rule: rotation and position.

Another way to check modifications is by clicking on the “Override” button at the top of the inspector. After doing so, a brief list of all the modified attributes pops up, separated by component. This allows to compare the modified values with the default one side-by-side. You can also revert single values to its original value, to offer a more granular control.

Editing already-existing prefabs has always been a pain in Unity. To do this, you had to:

  1. Make an instance of the prefab in the current scene
  2. Edit that instance
  3. Apply the changes to the prefab pressing an “Apply” button
  4. Removing from the scene the instance that you used to set the modifications

In 2018.3, Unity introduces “Prefab mode” to solve this problem. “Prefab mode” is an isolated environment to edit prefabs, without polluting other scenes. Here you can edit a prefab, without having to pollute other scenes. Modifications get saved automatically without any explicit command. When the modifications are over, you can return to the scene. You will see all the instances of your prefab have changed together with the prefab.

There are many ways to access prefab mode. Here are some:

  • Select a prefab inside a folder. A button “Open prefab” will appear in the inspector, that will take you to prefab mode.
  • Double-click a prefab inside a folder.
  • Select an instance of a prefab in the scene, and a button will appear on the top of the inspector with the label “Open”.
  • In the Hierarchy view, next to any instance of a prefab, there is a small arrow pointing to the right. if you click on in, it will take you a prefab mode.

To get out of prefab mode, there are also many possibilities. For instance, you can:

  • Click on the left-pointing arrow next to the prefab name , on the hierarchy tab.
  • Click on the scene name at the beginning of the breadcrums, on top of the scene view.

One of the biggest announcements for Unity 2018.3 is the introductions of nested prefabs. Finally! This is how it works.

In the prefabs folder you have 2 prefabs prepared for you: “Chest” and “Coin”. If you want that your chest has always at least one coin, it would make sense to nest the coin inside the chest prefab.

Before Unity 2018.3, if you drag the coin into the chest, that coin has lost its connection with the original prefab. That means that if you were to change the prefab “Coin”, the one inside the chest would not update.

But with the nested prefabs, that changes completely. Go into prefab mode for the chest, and drop a couple of coins inside it.

You will realize that the icon next to the coin is blue, while the others are gray. This behavior is the same as the one explained at the beginning of the article. This means that for the chest, the coin is an external reference. Any changes to the coin will transition to the coin inside the chest.

To test this, let’s go to prefab mode and edit the scale of our Coin prefab. If you then go to prefab mode for the chest, and check the coin inside it, you will see it also changed in size.

Great! Now you do now have to worry anymore when you change a prefab. You will not have to chase around copies of that prefab, inside other prefabs.

Sometimes you may want to instantiate not only copies of a prefab, but also variations of that prefab. Enter prefab variants.

Let’s say you are building a dungeon level, and you wish to instantiate many chests. Some of them will be empty, some will contain one or two coins. The first thing that you will do is to make 2 variants of your chest. To do this, click on the prefab with the right mouse-button and select “Create > Prefab Variant”.

In this case you will build 2 variations of the chest, one for a chest with 1 coin, and another one with 2 coins. So create 2 prefab variants, change their names, and add coins using prefab mode.

Now there are 2 variants of the chest: with 1 coin, and with 2 coins. Next step is to spread them around the level.

The chests are in position, and you could start building the rest of the level. But imagine that after a while you realize that you forgot to close the chest! Usually this would mean going to the 3 prefabs we used to create the chests. But in this case, the chests with coins are a variant of the empty one. So you can edit the empty chest in Prefab mode to close the lid on the chest.

Now if you return to the scene… magic! Not only the instances of the empty chest, but also its variations have their lids closed as well. Every chest applied the modification in the lid, while still retaining its differences. The other chests still keep their coins, while having closed their lids.

This feature gives a much more powerful approach to editing and structuring prefabs. The amount of editing gets minimizing, making easier to maintain prefabs.

The new workflow will make your life much easier, and might cure headaches that are experiencing in your projects. Try to open your games with Unity 2018.3, and test how it can help you improve the organization of your game object.

If you would like to see more demonstrations of people using the new workflow, I recommend to watch this video by Brackeys, where he goes through all this features one by one.

Also don’t forget to download the starter package to have all the assets used in this article, or the final package if you want to work on the elements created at the end of it.

If you have any questions or comments, please join the forum discussion below.

Enrique Moreno Tent

Contributors

Enrique Moreno Tent

Author

Gijs Bannenberg

Tech Editor

Over 300 content creators. Join our team.