Unity-Technologies/UnityCsReference · error · ArgumentException

No material targets provided

Error message

No material targets provided

What it means

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.

Source

Thrown at Editor/Mono/MaterialProperty.cs:207

                object previousValue = m_TextureScaleAndOffset;
                m_TextureScaleAndOffset = value;
                ApplyProperty(previousValue, changedMask);
            }
        }

        private void ApplyProperty(object newValue)
        {
            m_MixedValueMask = 0;
            object previousValue = m_Value;
            m_Value = newValue;
            ApplyProperty(previousValue, 1);
        }

        private void ApplyProperty(object previousValue, int changedPropertyMask)
        {
            if (targets == null || targets.Length == 0)
                throw new ArgumentException("No material targets provided");

            Object[] mats = targets;
            string targetTitle;
            if (mats.Length == 1)
                targetTitle = mats[0].name;
            else
                targetTitle = mats.Length + " " + ObjectNames.NicifyVariableName(ObjectNames.GetClassName(mats[0])) + "s";

            //@TODO: Maybe all this logic should be moved to C++
            // reduces api surface...
            bool didApply = false;
            if (m_ApplyPropertyCallback != null)
                didApply = m_ApplyPropertyCallback(this, changedPropertyMask, previousValue);

            if (!didApply)
                ShaderUtil.ApplyProperty(this, changedPropertyMask, "Modify " + displayName + " of " + targetTitle);

            foreach (Material material in targets)

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Check materialProperty.targets is non-null and non-empty before assigning to the property.
  2. Ensure the MaterialEditor/MaterialProperty context has an active material selection.
  3. Guard against transient null targets during selection changes or domain reloads.

Example fix

// before
prop.floatValue = newValue;

// after
if (prop.targets == null || prop.targets.Length == 0)
    return;
prop.floatValue = newValue;
Defensive patterns

Strategy: validation

Validate before calling

if (materialProperty.targets == null || materialProperty.targets.Length == 0) return;

Type guard

static bool HasMaterialTargets(MaterialProperty p) => p != null && p.targets != null && p.targets.Length > 0;

Try / catch

try { materialProperty.floatValue = v; }
catch (ArgumentException ex) when (ex.Message == "No material targets provided") { Debug.LogWarning("No active material selection; skipping."); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/a3022fc81db1362c. Report an issue: GitHub.