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
- Hayba is installed and your agent is connected. See Getting started.
- You are in a scratch project, ideally under source control.
- Review each external edit is off. This guide creates assets, which the exact review cannot approve on this version. See What can be approved.
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
material_createcreates the material.material_add_nodeadds each expression, such asMaterialExpressionVectorParameterandMaterialExpressionScalarParameter.material_connect_nodeswires each node to a material input or to another node.material_validatechecks the graph without compiling.material_compilewrites the material to disk, applies staged settings and returns translator errors and shader stats.material_create_instanceandmaterial_set_parammake the red instance.material_applyassigns it to the actor.
Things worth knowing:
-
Some broken wiring makes Unreal's shader translator assert, which takes the whole editor
down: reroutes that lead nowhere, or links to output indices that do not exist.
material_validatefinds these without compiling, andmaterial_compileruns the same checks and refuses to compile if any fail. - Graph edits are not written to disk until
material_compile. Call it once the graph is complete. The same goes for material functions. - For a node with several outputs, such as a material function call, the agent must name the output pin. Hayba refuses the connection otherwise, because defaulting to the first output silently swaps outputs.
material_get_inforeturns the full graph, parameters and a list of dead nodes that feed no output.- To use the material on spline meshes, set
used_with_spline_mesheswithmaterial_set_propertybefore compiling.
Check the result
- Ask for
material_get_infoon the instance to confirm the parameter value. - Ask the agent to frame the cube and capture the viewport. See Place actors and capture the viewport.
- Open
M_Paintedin the material editor.