{"record":{"id":"a3022fc81db1362c","repo":"Unity-Technologies/UnityCsReference","slug":"no-material-targets-provided","errorCode":null,"errorMessage":"No material targets provided","messagePattern":"No material targets provided","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/MaterialProperty.cs","lineNumber":207,"sourceCode":"\n                object previousValue = m_TextureScaleAndOffset;\n                m_TextureScaleAndOffset = value;\n                ApplyProperty(previousValue, changedMask);\n            }\n        }\n\n        private void ApplyProperty(object newValue)\n        {\n            m_MixedValueMask = 0;\n            object previousValue = m_Value;\n            m_Value = newValue;\n            ApplyProperty(previousValue, 1);\n        }\n\n        private void ApplyProperty(object previousValue, int changedPropertyMask)\n        {\n            if (targets == null || targets.Length == 0)\n                throw new ArgumentException(\"No material targets provided\");\n\n            Object[] mats = targets;\n            string targetTitle;\n            if (mats.Length == 1)\n                targetTitle = mats[0].name;\n            else\n                targetTitle = mats.Length + \" \" + ObjectNames.NicifyVariableName(ObjectNames.GetClassName(mats[0])) + \"s\";\n\n            //@TODO: Maybe all this logic should be moved to C++\n            // reduces api surface...\n            bool didApply = false;\n            if (m_ApplyPropertyCallback != null)\n                didApply = m_ApplyPropertyCallback(this, changedPropertyMask, previousValue);\n\n            if (!didApply)\n                ShaderUtil.ApplyProperty(this, changedPropertyMask, \"Modify \" + displayName + \" of \" + targetTitle);\n\n            foreach (Material material in targets)","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/MaterialProperty.cs#L189-L225","documentation":"Thrown by MaterialProperty.ApplyProperty when the targets array (the materials the property applies to) is null or empty. ApplyProperty is the internal path that pushes a new value into one or more materials, and it requires at least one target material.","triggerScenarios":"Modifying a MaterialProperty whose targets were never set or were cleared — e.g. a MaterialProperty obtained from a MaterialEditor that has no selection, or operating on a property after the target materials were destroyed/released.","commonSituations":"A custom shader/material inspector that reads a MaterialProperty and sets its value before the editor bound any materials. Undo/redo or selection change that nulls out targets mid-edit.","solutions":["Check materialProperty.targets is non-null and non-empty before assigning to the property.","Ensure the MaterialEditor/MaterialProperty context has an active material selection.","Guard against transient null targets during selection changes or domain reloads."],"exampleFix":"// before\nprop.floatValue = newValue;\n\n// after\nif (prop.targets == null || prop.targets.Length == 0)\n    return;\nprop.floatValue = newValue;","handlingStrategy":"validation","validationCode":"if (materialProperty.targets == null || materialProperty.targets.Length == 0) return;","typeGuard":"static bool HasMaterialTargets(MaterialProperty p) => p != null && p.targets != null && p.targets.Length > 0;","tryCatchPattern":"try { materialProperty.floatValue = v; }\ncatch (ArgumentException ex) when (ex.Message == \"No material targets provided\") { Debug.LogWarning(\"No active material selection; skipping.\"); }","preventionTips":["Check targets before setting property values","Ensure an active material selection","Guard against null targets during selection changes"],"tags":["unity","editor","material","shader","argument-validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}