Skip to content

Create and validate a material

Have an agent build a material graph, check it for wiring that can crash the shader translator, compile it, and make an instance with its own parameter values.

Before you start

Prompt

Prompt
Create a material M_Painted in /Game/Hayba/Materials with a vector parameter BaseColor (default mid grey) wired to Base Color and a scalar parameter Roughness (default 0.6) wired to Roughness. Validate the graph before compiling, then compile and report any errors. Make an instance MI_Painted_Red with BaseColor set to red, and apply it to the actor named Cube.

What the agent does

  1. material_create creates the material.
  2. material_add_node adds each expression, such as MaterialExpressionVectorParameter and MaterialExpressionScalarParameter.
  3. material_connect_nodes wires each node to a material input or to another node.
  4. material_validate checks the graph without compiling.
  5. material_compile writes the material to disk, applies staged settings and returns translator errors and shader stats.
  6. material_create_instance and material_set_param make the red instance.
  7. material_apply assigns it to the actor.

Things worth knowing:

Check the result