Materials and shader properties
↑How it works and why
Section titled “How it works and why”A shader defines how a surface is drawn. A material chooses a shader and stores its property values: textures, base color, metallic, smoothness, transparency and similar controls. A MeshRenderer references one or more materials. Changing the shader can change which properties a material exposes.
For URP use a URP-compatible shader such as Universal Render Pipeline/Lit. Built-In pipeline shader examples are not necessarily drop-in compatible with URP or HDRP. Texture and material assets are separate; one texture can be reused by several materials.
Example you can try
Section titled “Example you can try”using UnityEngine;
public sealed class TintRenderer : MonoBehaviour{ [SerializeField] private Renderer target; private static readonly int BaseColor = Shader.PropertyToID("_BaseColor"); private MaterialPropertyBlock block;
public void SetColor(Color color) { if (target == null) return; block ??= new MaterialPropertyBlock(); target.GetPropertyBlock(block); block.SetColor(BaseColor, color); target.SetPropertyBlock(block); }}When to use it and what can go wrong
Section titled “When to use it and what can go wrong”Why a property block? It changes per-renderer shader properties without creating a separate material instance, although batching behavior depends on the render pipeline (especially SRP Batcher). Pitfall: renderer.material may instantiate a copy; sharedMaterial edits affect every user of the asset in the Editor.
Try it: Make two objects share a material; change only one object’s color at runtime with a property block.
