# Material Override

> Aego 0.12.5 · development; docs build `4a32b816933e02930662f6a443cb25abe6050d090c55e237cbff5c44ae9b25f8`. [Build manifest](/docs-build.json).

```
component engine.MaterialOverride
```

Overrides up to eight numeric shader parameters on this node. Removed parameters remain in the values list.

Use this component when two nodes share a material but need different numerical values. Its Inspector shows declared instance parameters and their inherited values. Save edit-mode overrides with the scene; changes in Play affect the play copy, not the shared `.aemat` source.

Setters take the shader parameter's exact `name`, such as `Flash`, not an AssetID or a post-processing instance key. The declared type must match the setter and the parameter must allow `@instance` overrides. Floating-point lanes must be finite, integers must fit int32, and a node supports at most eight active explicit parameters. A shader's Inspector range is not a promise that script setters clamp values into that range.

Getters read the effective value after shader defaults, material values and this node's overrides. Reset removes an explicit value instead of storing the current inherited value. Removed shader parameters remain in `values` for restoration, but are not submitted as active shader values. [PostProcess](/ref/render2d.PostProcess.md) uses a different, effect-instance scope.

## One-node Flash example

Attach this script to a SpriteRenderer node with MaterialOverride, then start Play. It assigns the built-in Flash material, writes one override and resets it. The log shows the inherited value, the override, whether Reset removed a value, and the inherited value again. Without that node setup, the script reports the missing components instead of silently skipping the example.

```aes check
package demo

import (
    "aego/log"
    "aego/material"
)

script FlashProbe {
    func Ready() {
        sprite := node.Get<SpriteRenderer>()
        values := node.Get<MaterialOverride>()
        if sprite == nil || values == nil {
            log.Error("FlashProbe needs SpriteRenderer and MaterialOverride")
            return
        }
        material.Assign(node, material.Builtin("Flash"))
        inherited := values.GetFloat("Flash")
        values.SetFloat("Flash", 0.65)
        log.Info("inherited=" + string(inherited) + ", explicit=" + string(values.GetFloat("Flash")))
        removed := values.Reset("Flash")
        log.Info("reset=" + string(removed) + ", inherited=" + string(values.GetFloat("Flash")))
    }
}
```

## Fields

| Name | Script name | Type | Default | Description |
|---|---|---|---|---|
| Values | `Values` | `[]engine.MaterialParameter` | `[]` | Explicit typed values. Absent values inherit the shared material; removed shader fields remain serialized. |

## GetBool

```
func (MaterialOverride) GetBool(name string) bool
```

Reads the effective bool parameter.

Returns the effective typed boolean. This does not treat a numerical zero or nonzero shader parameter as a bool.

## GetColor

```
func (MaterialOverride) GetColor(name string) Color
```

Reads the effective linear Color of a parameter declared with the color hint.

Returns the effective linear Color of a parameter declared with the colour hint. This is not a colour conversion for an ordinary vec4.

## GetFloat

```
func (MaterialOverride) GetFloat(name string) float
```

Reads the effective float after shader default, material value and node override.

`name` selects a declared float parameter. The result includes inheritance when this node has no explicit value; an unresolved material or incompatible type faults the script.

## GetInt

```
func (MaterialOverride) GetInt(name string) int
```

Reads the exact signed int32 effective parameter.

Returns the effective signed int32 value as a script `int`, without a floating-point round trip. The declared parameter must have integer type.

## GetVec2

```
func (MaterialOverride) GetVec2(name string) Vec2
```

Reads the effective vec2 parameter.

Returns the two effective components of a declared vec2. The getter does not truncate a larger vector.

## GetVec3

```
func (MaterialOverride) GetVec3(name string) Vec3
```

Reads the effective vec3 parameter.

Returns the three effective components of a declared vec3. The getter does not truncate a larger vector.

## GetVec4

```
func (MaterialOverride) GetVec4(name string) aego/material.Vec4
```

Reads four numerical effective lanes as material.Vec4, without color conversion.

Returns a numerical [material.Vec4](/ref/aego/material.Vec4.md). A parameter with the colour hint requires GetColor instead.

## GetVec4Lane

```
func (MaterialOverride) GetVec4Lane(name string, lane int) float
```

Reads one lane from an ordinary vec4 parameter. The lane index must be from 0 through 3.

`lane` is 0 for X, 1 for Y, 2 for Z or 3 for W of an ordinary vec4. An out-of-range lane or colour parameter faults the script.

## Reset

```
func (MaterialOverride) Reset(name string) bool
```

Removes the explicit instance value and inherits the shared material value. Returns whether an explicit value existed.

Removes this node's explicit value for `name`, including a retained value for a removed shader parameter. Returns false when no explicit value was stored; it does not zero the shared material.

## SetBool

```
func (MaterialOverride) SetBool(name string, value bool)
```

Sets an instance bool parameter on this node.

`name` selects a bool parameter marked `@instance`. This is a typed boolean assignment, not an integer or float conversion.

## SetColor

```
func (MaterialOverride) SetColor(name string, value Color)
```

Sets a linear Color instance parameter declared with the color hint.

`value` is a linear Color for a vec4 parameter with the colour hint and `@instance`. The call does not interpret numerical Vec4 values as colours.

## SetFloat

```
func (MaterialOverride) SetFloat(name string, value float)
```

Sets an instance float parameter on this node. Type mismatch leaves its previous value unchanged.

`name` selects a float parameter marked `@instance`. `value` must be finite; the call writes only this node's override and does not save the scene or shared material.

## SetInt

```
func (MaterialOverride) SetInt(name string, value int)
```

Sets an exact signed int32 instance parameter. Values outside the int32 range are rejected.

`value` must fit signed int32, even though the script's `int` is wider. A range or type error leaves the old override unchanged.

## SetVec2

```
func (MaterialOverride) SetVec2(name string, value Vec2)
```

Sets an instance vec2 parameter on this node.

`value` supplies two finite components for a declared instance vec2. A different vector size is a type error.

## SetVec3

```
func (MaterialOverride) SetVec3(name string, value Vec3)
```

Sets an instance vec3 parameter on this node.

`value` supplies three finite components for a declared instance vec3. A different vector size is a type error.

## SetVec4

```
func (MaterialOverride) SetVec4(name string, value aego/material.Vec4)
```

Sets four numerical instance lanes using material.Vec4 without color conversion.

`value` is a numerical [material.Vec4](/ref/aego/material.Vec4.md). Use SetColor instead when the shader declares a colour parameter; these types are not interchangeable.
