Unity-Technologies/UnityCsReference · error · ArgumentException

The elementName argument can't be null or empty.

Error message

The elementName argument can't be null or empty.

What it means

OpenAndScrollToElement navigates to a VisualElement by name; a null/empty elementName cannot match anything, so it throws ArgumentException immediately.

Source

Thrown at Editor/Mono/Inspector/GraphicsSettingsInspectors/GraphicsSettingsInspectorUtility.cs:363

        static readonly List<Foldout> k_Foldouts = new();

        public static void OpenAndScrollTo(string propertyPath)
        {
            if (string.IsNullOrEmpty(propertyPath))
                throw new ArgumentException(nameof(propertyPath), $"The {nameof(propertyPath)} argument can't be null or empty.");

            OpenAndScrollTo<PropertyField, PropertyField>(
                root => TryFindPropertyAndTabByBindingPath(propertyPath, root, out var tabbedView, out var tabButton, out var propertyField)
                    ? (true, tabbedView, tabButton, propertyField)
                    : (false, null, null, null),
                () => $"Couldn't find a property with bindingPath {propertyPath} in the settings container.",
                (scrollView, _, propertyField, _) => OpenFoldoutsThenScroll(propertyField, scrollView));
        }

        public static void OpenAndScrollToElement(string elementName)
        {
            if (string.IsNullOrEmpty(elementName))
                throw new ArgumentException(nameof(elementName), $"The {nameof(elementName)} argument can't be null or empty.");

            OpenAndScrollTo<VisualElement, VisualElement>(
                root => TryFindElementAndTabByName(elementName, root, out var tabbedView, out var tabButton, out var element)
                    ? (true, tabbedView, tabButton, element)
                    : (false, null, null, null),
                () => $"Couldn't find an element with name {elementName} in the settings container.",
                (scrollView, _, element, _) => OpenFoldoutsThenScroll(element, scrollView));
        }

        public static void OpenAndScrollTo(Type renderPipelineGraphicsSettingsType)
        {
            OpenAndScrollTo<PropertyField>(renderPipelineGraphicsSettingsType);
        }

        public static void OpenAndScrollTo<TGraphicsSettings>(string propertyPath = "")
            where TGraphicsSettings : IRenderPipelineGraphicsSettings
        {
            OpenAndScrollTo<TGraphicsSettings, PropertyField>(p => p.bindingPath.Contains(propertyPath));

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Check elementName is non-null and non-empty before calling.
  2. Ensure the element you target actually has its name set in UXML/code before invoking.
  3. Use string.IsNullOrWhiteSpace guard at the call site.

Example fix

// before
OpenAndScrollToElement(null); // throws

// after
if (!string.IsNullOrWhiteSpace(elementName))
    OpenAndScrollToElement(elementName);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(elementName))
    throw new ArgumentException("elementName required", nameof(elementName));
GraphicsSettingsInspectorUtility.OpenAndScrollToElement(elementName);

Prevention

When it happens

Trigger: Calling GraphicsSettingsInspectorUtility.OpenAndScrollToElement(null) or OpenAndScrollToElement("").

Common situations: Forwarding an element name that was never set. Binding code passing a default/empty string. Looking up by a name field that failed to populate.

Related errors


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