# Material Inheritance > **Notice:** The sections below cover advanced manual material development: material definitions, inheritance, and rendering integration. **The recommended way to create materials is through the visual, node-based [Material Editor](../../../content/materials/index.md), which provides an approachable workflow without writing material and shader code by hand.** Material inheritance supports two kinds of reuse. An abstract material supplies declarations and code for building a base material. A derived material uses an existing base definition and inherits settings from its parent. These relationships act at different levels. Understanding which one you are changing helps determine whether a change affects the available shader programs and inputs, or the values used by a particular material. For the roles of graphs, files, and loaded materials, see [Material System Overview](../../../code/materials_shaders/material_system/index.md). ## Two Parent Relationships | Relationship | Parent | Result | |---|---|---| | Abstract description inheritance | An abstract material referenced by a ULON description. | A combined description that defines one base material. | | Derived material inheritance | A base material or another derived material. | A material that shares the base definition and can override its parent's editable settings. | The same word, *parent*, is used for both relationships, but the reference identifies a different kind of resource. In a ULON base or abstract description, it selects an abstract description. In a derived material, it identifies another material in the loaded hierarchy. A base material can use an abstract description, or contain all the declarations it needs itself. One base material does not inherit another base material through the derived-material mechanism. A graph-generated base follows the same distinction: using an abstract description during generation or loading does not make that description a runtime parent material. ## Building a Base from an Abstract Description An [abstract material](../../../code/materials_shaders/abstract_materials/index.md) is a reusable ULON description stored in an `*.abstmat` file. It can provide inputs, default values, shader sources, passes, and other declarations. It is not a separate material that can be assigned to a surface. The *parent* argument selects one abstract description by its registered name: the file name without the extension, prefixed with *namespace::* when the abstract description declares a namespace. This is a name lookup among abstract descriptions, rather than a path to any material file. The descriptions are combined as follows: 1. If the abstract parent has its own abstract parent, that relationship is expanded first. 2. Missing root arguments are copied from the parent. An argument already present in the child keeps its own value; strings and arrays are not combined element by element. 3. The parent's child nodes are copied before the child's own nodes. 4. Repeated declarations follow the rules for their record type. The result is one base definition. The abstract description does not become an intermediate object between the base and its derived materials. Its *parent* argument is consumed during expansion. The base's manual mode, name, and GUID are established independently of its abstract parent. Declare the required identity settings on the base itself. Inherited *manual*, *namespace*, and *guid* arguments do not change that identity. See [ULON Base Material File Format](../../../code/formats/materials_formats/ulon_base_material_format.md) for the root arguments. The [reusable Mesh foundation example](../../../code/materials_shaders/abstract_materials/index.md#creating_material) shows two bases sharing one abstract description. Reloading after a shared code change updates both bases, while saved derived value overrides retain their own values. ## Repeated Declarations Are Processed by Type Expanding an abstract parent preserves both its declarations and the child's declarations. Repeating a name does not mean that the child replaces the whole parent node. Each kind of declaration has its own processing rules. | Declaration | Effect of repeating a name | |---|---| | [States](../../../code/formats/materials_formats/ulon_materials/states.md) and ordinary numeric [parameters](../../../code/formats/materials_formats/ulon_materials/parameters.md) | The first declaration establishes the definition, including its type. Later declarations can change its value without redefining that structure. Array parameters have separate initialization rules. | | [Shader](../../../code/formats/materials_formats/ulon_materials/shaders.md) and [Script](../../../code/formats/materials_formats/ulon_materials/scripts.md) sources | The source texts are joined in declaration order. Defining a function again does not replace its earlier definition. | | [Options](../../../code/formats/materials_formats/ulon_materials/options.md) | Later declarations update the value. Editability and the Editor control are established by the first declaration. | | [Textures](../../../code/formats/materials_formats/ulon_materials/textures.md) | The first declaration establishes the type, source, shader name, and bindings. Later declarations reset and set the resource and sampling settings, using defaults for omitted settings at that step. | | [Groups](../../../code/formats/materials_formats/ulon_materials/groups.md) | A later group with *merge_group=true* adds its controls to the most recently created group with that name. The earlier group does not need this flag. Without merging, a separate Editor group is created. Group nesting does not create separate namespaces for input names. | | [Passes](../../../code/formats/materials_formats/ulon_materials/passes.md) | Each declaration adds a pass variant. Shader stages are not merged between same-named passes; shader lookup selects the first suitable variant for the requested geometry type and evaluated conditions. | Named expressions remain separate entries, with name-based calls selecting the last entry. Their bodies are not joined like Script sources. Abstract inheritance has no general operation for deleting an inherited record. For example, adding a pass with the same name as an unconditional parent pass does not guarantee that the new pass will be selected. Design the abstract description's conditions and code extension points to allow the intended customization. The individual format references describe the rules for each declaration. ## Inheriting Values from a Material A derived material has an immediate parent and a base material. The immediate parent supplies inherited values; the base defines the available parameters, texture inputs, states, shader sources, and passes. All materials in the branch use that base definition. For example, *RedPaint* can inherit from *Painted*, which inherits from *Coating_Base*. The immediate parent of *RedPaint* is *Painted*; its base is *Coating_Base*. Another child can use the same base with different settings. Inheritance operates separately for individual settings. A child can inherit a color, override roughness, and inherit a texture at the same time. The base controls which settings are editable; inheriting a material does not make a non-editable setting editable. Derived materials cannot add parameter declarations or replace shader source code through value overrides. Those changes belong to the base definition or its source graph. Changing a state can select a different shader variant, but the available variants still come from the base. ## Overrides and Propagation Each inheritable setting has an override status. Without an override, its effective value follows the immediate parent. With an override, the child supplies its own value, which can in turn be inherited by its children. Suppose the base declares an editable roughness parameter. Changing the override on *Painted* from 0.6 to 0.7 produces the following result: | Material | Immediate parent | Own roughness setting | Before | After | |---|---|---|---|---| | Coating_Base | None | Base default: 0.4 | 0.4 | 0.4 | | Painted | Coating_Base | Override: 0.6, changed to 0.7 | 0.6 | 0.7 | | RedPaint | Painted | Inherited | 0.6 | 0.7 | | RoughRedPaint | RedPaint | Override: 0.9 | 0.9 | 0.9 | The change reaches *RedPaint* because it has no roughness override. *RoughRedPaint* keeps its own value. Any of its children that inherit roughness continue to receive 0.9 from it. Overrides of other settings are unaffected. Resetting an override restores inheritance from the immediate parent. It does not necessarily restore the base default: resetting roughness on *RoughRedPaint* in this example gives 0.7, the current value inherited through *RedPaint*. An overridden value can happen to equal its parent's value and still remain an override. Comparing numbers alone is therefore insufficient to determine whether a setting follows its parent. Use the override status and a reset operation when you need to restore inheritance. ## Creating and Changing a Hierarchy Creating a child material in UnigineEditor establishes a parent relationship and lets you adjust the exposed settings. Assigning that child to a surface uses its effective settings, including inherited values. For the Editor workflow, see [Hierarchy and Inheritance](../../../content/materials/inheritance.md). In code, the [Material](../../../api/library/rendering/class.material_cpp.md) operations distinguish several changes: - *inherit()* creates a child of the source material. It shares the base definition and initially inherits its parent's settings. - *clone()* copies a derived material's settings and override status, retaining the same immediate parent. The source and the clone are siblings. This operation does not clone a base definition. - *resetParameter()*, *resetState()*, and *resetTexture()* remove the corresponding editable override and resume inheritance. - *setParent()* changes the parent of an eligible derived material. Its *save_all_values* argument controls preservation of values, so reparenting is more than replacing a reference. When reparenting across different bases, values are matched to available settings by name, subject to editability. Matching names do not guarantee matching meanings or compatible shader behavior. Check the resulting settings when changing the base of a material, and keep parent relationships acyclic. Creating a runtime child does not automatically create a file. A saved derived material uses the [User Material File Format](../../../code/formats/materials_formats/user_material_format.md) to record its identity, material references, and serializable overrides. If its immediate parent is the base itself, the base reference is sufficient and a separate parent reference can be omitted. The file does not contain a complete copy of the base's declarations or shader code.