fbpx
Overriding properties2019-03-24T03:02:50+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

Overriding Properties

Written by Max Plooi
Creator of Nested Prefabs for Unity

What are overridden properties?

Individual properties of a prefab instance can be overridden. The values of overridden properties will not be saved to the prefab asset and are unique for that single prefab instance.

And if the property value is changed in the original prefab asset, then the overridden property of the instance won’t be updated and will keep the overridden value. All other non-overridden properties will be updated with changes as usual.

Besides properties, you can also add an entirely new component or child to the prefab. If you do that then the entire component or child is marked as ‘overridden’ and the component or child won’t be saved in the prefab asset, only in that single prefab instance.

What can I use this for?

You can use overridden properties to make small variations on prefabs that are unique for a prefab instance. Such as multiple instances with a different color.

How to override a property

In the Hierarchy Window, select a game object that is part of a prefab and change the value of a property to override it. The property will show with a bold label and a blue line on the left side in the Inspector, indicating that the property is overridden for that prefab instance. This can be done for any property on any Game Object in the hierarchy of the prefab, or any nested prefab.

Overriding properties of a nested prefab

You can also override a property of a nested prefab and save it in the parent of the nested prefab. If you do that, then the value of the overridden property will be applied to the parent of the nested prefab and will also be updated in all instances of that parent prefab. Meaning that it is no longer unique for a single prefab instance.

But, because it is an overridden property, the value will not be applied to the original prefab asset of the nested prefab. The original prefab asset will keep its original value. This overridden value is unique for the parent prefab and all instances of the parent prefab.

How to save an overridden property

In a Prefab Instance

To save an overridden property, right-click on te property and click ‘Apply as Override in Prefab’ followed by tbe name of the prefab that you want to save the property value in.

Or, in the Hierarchy window, you can select the root prefab. And then click ‘Overrides’ in the Inspector, and click ‘Apply All’ to save all overridden properties in the root prefab at once. This can only be done for the root prefab, and not for other nested prefabs in the hierarchy.

In Prefab Mode

Alternatively, if you have not yet modified the value on the prefab instance, you can open the parent prefab (that you want to save the value in) in prefab mode. After opening prefab mode, override the property of the nested prefab by changing the value in the inspector and it will be automatically saved.

A few exceptions

The position and rotations of prefab instances are never applied to the original prefab asset and are always considered as overridden properties. For prefabs with a Rect Transform this includes the width, height, margins, anchors, and pivot.

This is because it is most common to have all prefab instances at different positions and rotations within your scene. And it is almost never the case that you need all prefab instances at the exact same position in your game.

Prefab Variants

Permanently override properties with Prefab Variants in the next article. Or take another look at how to Nest Prefabs in the previous article.

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: