Unity-Technologies/UnityCsReference · error · InvalidOperationException

renderingLayerNames is null or empty

Error message

renderingLayerNames is null or empty

What it means

Thrown by TryMigrateRenderingLayersToTagManager when renderingLayerNames is null or has zero length. Despite the Try* prefix, the method enforces non-empty input by throwing rather than returning false.

Source

Thrown at Editor/Mono/Inspector/RenderPipelineEditorUtility.cs:101

        public static bool TryRemoveLastRenderingLayerName()
            => TagManager.Internal_TryRemoveLastRenderingLayerName();

        [AutoStaticsCleanupOnCodeReload]
        public static Action onRenderingLayerCountChanged;

        /// <summary>
        /// Migrate Rendering Layers data from Global Settings to Tags and Layers.
        /// </summary>
        /// <param name="renderingLayerNames">A list of rendering layer names.</param>
        /// <typeparam name="T">Render Pipeline type.</typeparam>
        /// <returns>Returns true if it was succesful.</returns>
        /// <exception cref="InvalidOperationException">Throw an exception if rendering layer names list is null or empty.</exception>
        internal static bool TryMigrateRenderingLayersToTagManager<T>(string[] renderingLayerNames)
            where T: RenderPipeline
        {
            if (renderingLayerNames == null || renderingLayerNames.Length == 0)
                throw new InvalidOperationException("renderingLayerNames is null or empty");

            var renderPipelineFullName = typeof(T).FullName;
            var trimmedNames = new string[renderingLayerNames.Length];
            for (int i = 0; i < renderingLayerNames.Length; i++)
            {
                trimmedNames[i] = renderingLayerNames[i]?.Trim() ?? string.Empty;
            }

            return TagManager.TryMigrateRenderingLayers(renderPipelineFullName, trimmedNames);
        }

        internal static void ClearMigratedRenderPipelines()
        {
            TagManager.ClearMigratedRenderPipelines();
        }

        /// <summary>
        /// Retrieves the maximum number of rendering layers supported by the currently active render pipeline.

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Check renderingLayerNames != null && renderingLayerNames.Length > 0 before calling.
  2. Populate the rendering layer names list in the pipeline's global settings before migration.
  3. If no layers exist, skip migration rather than calling with an empty list.

Example fix

// before
RenderPipelineEditorUtility.TryMigrateRenderingLayersToTagManager<MyRP>(names);

// after
if (names != null && names.Length > 0)
    RenderPipelineEditorUtility.TryMigrateRenderingLayersToTagManager<MyRP>(names);
Defensive patterns

Strategy: validation

Validate before calling

bool ok = renderingLayerNames != null && renderingLayerNames.Length > 0;

Prevention

When it happens

Trigger: Calling TryMigrateRenderingLayersToTagManager with a null or empty string[] when migrating rendering layer names from a render pipeline's global settings to the Tags and Layers manager.

Common situations: Migrating rendering layers for a pipeline whose global settings have no layer names configured. Custom render pipelines that forgot to populate the layer name list. Running migration on a fresh project.

Related errors


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