0
0
Unityframework~10 mins

Material properties in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Material properties
Create Material
Assign Shader
Set Properties
Apply Material to Object
Render Object with Material
This flow shows how a material is created, given a shader, properties are set, then applied to an object for rendering.
Execution Sample
Unity
Material mat = new Material(Shader.Find("Standard"));
mat.color = Color.red;
mat.SetFloat("_Glossiness", 0.5f);
Renderer rend = GetComponent<Renderer>();
rend.material = mat;
This code creates a red material with medium glossiness and applies it to the object's renderer.
Execution Table
StepActionProperty ChangedValue SetEffect
1Create new Material with Standard shadershaderStandardMaterial ready with default properties
2Set color propertycolorredMaterial color changes to red
3Set glossiness property_Glossiness0.5Material surface becomes moderately shiny
4Get Renderer componentrenderercomponent foundReady to assign material
5Assign material to renderermaterialmatObject will render with red, glossy material
6Render frameN/AN/AObject appears red and shiny on screen
💡 All material properties set and applied; rendering completes.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 5Final
matnullMaterial(Standard)Material(Standard, color=red)Material(Standard, color=red, glossiness=0.5)Material(Standard, color=red, glossiness=0.5)Material(Standard, color=red, glossiness=0.5)
rendnullnullnullnullRenderer componentRenderer with mat assigned
Key Moments - 3 Insights
Why do we need to create a new Material instead of modifying the shared material?
Creating a new Material instance (step 1) ensures changes affect only this object. Modifying shared material changes all objects using it, which can cause unexpected results.
What happens if we set a property name incorrectly?
If the property name is wrong (like in step 3), the property won't change and no error appears. The material keeps its previous value, so always check property names carefully.
Why do we assign the material to the renderer instead of the object directly?
The Renderer component controls how the object looks. Assigning material to renderer (step 5) tells Unity what surface appearance to use when drawing the object.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the material's color after step 2?
ABlue
BRed
CDefault (white)
DGreen
💡 Hint
Check the 'Property Changed' and 'Value Set' columns at step 2 in the execution table.
At which step is the material assigned to the object's renderer?
AStep 3
BStep 1
CStep 5
DStep 6
💡 Hint
Look for the action 'Assign material to renderer' in the execution table.
If we skip setting the glossiness property, what will happen to the material's appearance?
AIt will keep the default glossiness value
BIt will be completely matte (no shine)
CIt will be fully shiny
DThe material will not render
💡 Hint
Refer to step 3 where glossiness is set; skipping it means the default remains.
Concept Snapshot
Material properties control how objects look in Unity.
Create a Material with a Shader.
Set properties like color and glossiness.
Assign the Material to the Renderer component.
Changes affect only that object’s appearance.
Full Transcript
In Unity, materials define how objects appear. First, you create a new Material and assign a shader to it. Then, you set properties such as color and glossiness to change its look. After that, you get the Renderer component of the object and assign the new material to it. This process ensures the object renders with the desired appearance. The execution table shows each step, including creating the material, setting properties, and applying it. Variables like 'mat' and 'rend' track the material and renderer states. Key points include why to create a new material instance, the importance of correct property names, and assigning materials to the renderer. The visual quiz tests understanding of these steps and their effects.