fbpx
Best Practices2019-03-24T03:00:28+00:00

Guides

Be an expert with our advanced guides and build beautiful high-quality games.
Get a head start and receive knowledge directly to your inbox:

Expert Workflows

“I am constantly updating and extending this guide. Let me know in the comments what you would like to know about!”
– Max

Best Practices

Increase the quality of your games and work better within your team with these best practices.

#1 Keep it simple

It is important that you can predict what effect a change to your prefab will have on your game. With too many variants, overrides, and nested prefabs your project gets too complex and you can no longer predict what will happen when you modify a value.

Keep the depth of prefabs as low as possible. And only create Prefab Variants or Nested Prefabs if it is actually necessary and improves your project.

#2 Limit the number of prefabs

It can be tempting to create a prefab from every single Game Object in your project. But it is best to keep a good balance between Game Objects and prefabs to prevent your project from turning into complex chaos. In general, create a prefab if:

Multiple copies

If you will use the Game Object (or a similar Game Object) in more than one place in your project. Creating a prefab from the Game Object will give you a single place to edit it, so you don’t have to manually copy changes between multiple Game Objects.

Not specific for a scene

If the Game Object is not specific for the scene it is in. Even if the Game Object is only used in a single scene. If the usage of that Game Object is not specific for the scene then it is better to save the Game Object as a prefab and put it in a well-structured folder. That way, it is easier and more intuitive to find the data and Game Objects that you want to edit.

For example, imagine you have a Game Object with a script that manages the game state, let’s call it the ‘Game State Manager’. You can put the Game State Manager in the first scene that is opened when you start the game. It makes sense to have the Game Object there, because that scene will be loaded first, meaning that the Game State Manager will be started when the game starts and can manage the game state from that moment on.

However, someone else in your team (or yourself, 6 months from now) might not know which scene is loaded first. So if they are looking to edit some settings in the Game State Manager then they won’t know what scene to open and where that Game Object is saved.

That is why, in this case, it is better to save the Game Object as a prefab in a specific folder. Then, anyone can find and edit the Game Object easily by searching through the folder structure in the project or doing a quick search in the search field.

Collaborating

If multiple people will work on the Game Object and the scene it is in at the same time. By creating a prefab from the Game Object you can separate the location where the data for that Game Object is saved. That will allow multiple people to work on the Game Object and scene separately.

#3 Be consistent

Establish guidelines on the hierarchy of prefabs, naming conventions, and folder structure of your project. And then follow these guidelines.

It might not always be easy to create all your prefabs according to the guidelines. Sometimes, the usage of your prefabs or the components on them do not fit entirely within these guidelines.

However, it is worth the effort to slightly modify the scripts and/or components in your prefabs to match them with the guidelines. Consistency throughout your project is more valuable than a quick and easy solution for a single prefab. In the long run, it will save you countless hours and headaches if you spent some additional time to create a prefab that is consistent with the rest of your project.

Having consistency for all the prefabs in your project enables you to make predictions on where prefabs are and what they are used for, even if someone else created them and you have never seen them before. It also helps you to find the prefabs you need in your project folders and/or scenes.

#4 Separate prefabs by functionality

Put all the Game Objects that share the same functionality in a single prefab. And separate Game Objects that have different functionality. For example, don’t put a Button and a UI Manager in the same prefab.

Grouping Game Objects with the same functionality in a prefab makes it easier to find the Game Objects that you are looking for. It also helps with collaborating and prevents merge errors and conflicts.

#5 Override properties in the prefab it applies to

When overriding properties. Think about which prefab in the hierarchy these properties apply to in terms of functionality. If you are overriding the color of a door to match with the color palette of a house, override it in the house. If you are matching it to the color palette of the neighborhood. Override it in the neighborhood, not in the house.

#6 Use prefab mode

Use prefab mode to edit prefabs. It is possible to edit prefabs directly in the hierarchy and then apply those modified properties to the original prefab. But doing that increases the chances of accidentally overriding properties that you did not want to override, or to apply properties that you did not want to apply. Taking those additional 2 seconds to open the prefab in prefab mode is worth it.

#7 Give Feedback and Communicate

Giving feedback and communicating with your team and other game developers are the most important things you can do to increase the quality of your game. Let your team know what a prefab is used for and write documentation or a wiki.

Also, let me know in the comments what it is that you are struggling with, what you want to learn, or if something is missing in this guide. That way we can extend this guide with more useful information for you.

#8 Seriously. Keep it simple

This is so important, it is worth mentioning again (see #1). Just because you can create a prefab variant of every prefab, and nest every prefab in your project, that doesn’t mean you should.

It is great to have all prefabs, prefab variants, and nested prefabs in your project automatically updated with changes. But if you have to search for an hour to find that one prefab to edit to make the correct change, then it is not going to improve your workflow.

Get a head start

Become an expert by reading more of our advanced guides and build beautiful high-quality games. Get a head start and receive knowledge directly to your inbox:

Your thoughts

Let us know what you think. If you have any feedback, ideas, or just something awesome to say. We would love to start a conversation with you: