Overview
- Inheritance is a relationship where child objects receive values from an original parent object
- A parent object defines specific properties and values, from which inheriting child objects draw their values; if changes occur to the parent object, inheriting child objects will reflect those changes automatically
- An override is when a value set on a child object prevails over and replaces a value inherited from a parent object; an override is a feature of inheritance relationships, and has specific design and workflow patterns
When to use inheritance
Inheritance offers several advantages over individually setting values for each object:
- Accelerate changes - when adjustments are made to a parent object, child objects automatically inherit those values without requiring additional time for manual input
- Object management - inheritances allow easier management of large numbers of child objects that would otherwise require individual configuring and tracking
- Reduce errors - inherited values accurately cascade down to child objects without the risk of incorrect values being introduced whenever values are manually entered
- Reduce data redundancy and compiling speed - data values of child objects do not need to be stored and will not add additional burden to the compiling process
Terminology and diagram
Object
An object is a foundational aspect of inheritance relationships
An object is an entity or asset defined using specific properties.
Examples of objects in the Editor include:
- GameObjects
- Prefabs
- Materials
- VisualElements
Property and value
Properties and values are foundational aspects of inheritance relationships
A property is an object parameter that stores a value. The property definition should designate the specific type of value the property can store.
Examples of properties include:
- GameObject / Prefab: Position, rotation, camera component
- Material: Rendering mode, emission
- VisualElement: Text attributes, font family
Inheritance
Inheritance is a relationship between an original object and its object instances
Inheritance is a relationship between a parent object and its child objects.
A parent object defines specific properties and values, from which child objects will derive their values; if the parent object’s values change, the child objects will reflect those changes.
Instance
An instance of an object inherits properties and values from its parent
An instance of an object is a single occurrence of an original object and, in the context of inheritance, refers to child objects that inherit properties and values from its parent.
Instances are a reference to the parent object, and may be stored in, or “live" in, a different place than the parent objects. For example, while Prefab objects are stored in the Project, Prefab instances are stored in the Hierarchy of the Scene.
Anatomy and UI
Override bar
The override bar is the visual signifier that denotes the presence of an override on the property.
Layout
- It appears on the left side of the label of a property in an inspector
- Its height is the same as the entirety of the property it is overriding
- If the override exists for an entire inspector component, ensure that the override bar appears on the inspector component header, and the entire height of the inspector component with no line breaks.
- For example, if a user adds a new inspector component to a Prefab instance that the original Prefab did not have, an override bar would appear on the entire inspector component. In essence, the user is overriding an inherited value of “null” for that inspector component by adding it on the instance.
Style
The color of all other override bars (eg. Materials)
.unity-binding__prefab-override-bar-not-applicable
The color of the override bar for a Prefab override when disabled
.unity-binding__prefab-override-bar
The color of the override bar for a Prefab override
Use bold labels to highlight overrides
The label that the override appears next to should appear bolded; this provides a subtle reinforcement of the override bar signifier.
Interactable area
- When including features to manipulate an override, ensure that the interactable area is large enough by including the overridden property label