Aego Русский

Material Override

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 uses a different, effect-instance scope.

On this page

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.

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")))
    }
}
component engine.MaterialOverride

Art Studio

Emission and normal channels Art Studio lessons

Try it

Override one material instance

Both sprites share the Flash material and inherit Flash 0. The selected sprite has a disabled Set Flash script.

Enable the Set Flash script in the Inspector. After the scene restarts its Ready method sets the selected node's actual Flash override to 1; the other sprite remains unchanged. Reset disables the script and restores inheritance.

Starts the scene; open the example parameters to experiment.
Open in AegoDownload example project
Scene3 nodes
Flash instance
Transform
position[-2, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")materialAssetRef<material>asset("ae900000000000000000000000000c02")tintColor#38bdf8ffsizeVec2[2.5, 2.5]
Material Override
values[]engine.MaterialParameter[]
Reference instance
Transform
position[2, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")materialAssetRef<material>asset("ae900000000000000000000000000c02")tintColor#38bdf8ffsizeVec2[2.5, 2.5]
Material Override
values[]engine.MaterialParameter[]
Camera
Transform
position[0, 0]rotation0scale[1, 1]
Camera 2D
zoomfloat40clearColorColor#111827ffscaleenumfitVirtualvirtualVec2[960, 540]activebooltrue
Scriptmain.aes
package demo

// Enabling this attachment writes the actual node-local shader parameter.
// The other sprite retains the same shared material and inherits Flash 0.
script SetFlash {
    func Ready() {
        node.Get<MaterialOverride>().SetFloat("Flash", 1)
    }
}

Fields

NameTypeDefaultDescription
Values[]engine.MaterialParameter[]

Explicit typed values. Absent values inherit the shared material; removed shader fields remain serialized.

not in scripts

Methods

GetBool method

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 method

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 method

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 method

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 method

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 method

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 method

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

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

Returns a numerical material.Vec4. A parameter with the colour hint requires GetColor instead.

GetVec4Lane method

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 method

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 method

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 method

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 method

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 method

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 method

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 method

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 method

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. Use SetColor instead when the shader declares a colour parameter; these types are not interchangeable.