Unity-Technologies/UnityCsReference · error · ArgumentNullException

assetOrMetaFilePaths

Error message

assetOrMetaFilePaths

What it means

Thrown by AssetDatabase.CanOpenForEdit when the assetOrMetaFilePaths array is null. The method forwards to AssetModificationProcessorInternal.CanOpenForEdit which iterates the paths; a null array has no elements and no Length, so the guard throws ArgumentNullException(nameof(assetOrMetaFilePaths)) before profiling/VCS lookup.

Source

Thrown at Editor/Mono/AssetDatabase/AssetDatabase.cs:108

        }

        [RequiredByNativeCode]
        private static void Internal_CallImportPackageFailed(string packageName, string errorMessage)
        {
            foreach (var evt in m_importPackageFailedEvent)
                evt(packageName, errorMessage);
        }

        [RequiredByNativeCode]
        private static bool Internal_IsOpenForEdit(string assetOrMetaFilePath)
        {
            return IsOpenForEdit(assetOrMetaFilePath);
        }

        public static void CanOpenForEdit(string[] assetOrMetaFilePaths, List<string> outNotEditablePaths, [uei.DefaultValue("StatusQueryOptions.UseCachedIfPossible")] StatusQueryOptions statusQueryOptions = StatusQueryOptions.UseCachedIfPossible)
        {
            if (assetOrMetaFilePaths == null)
                throw new ArgumentNullException(nameof(assetOrMetaFilePaths));
            if (outNotEditablePaths == null)
                throw new ArgumentNullException(nameof(outNotEditablePaths));
            UnityEngine.Profiling.Profiler.BeginSample("AssetDatabase.CanOpenForEdit");
            AssetModificationProcessorInternal.CanOpenForEdit(assetOrMetaFilePaths, outNotEditablePaths, statusQueryOptions);
            UnityEngine.Profiling.Profiler.EndSample();
        }

        public static void IsOpenForEdit(string[] assetOrMetaFilePaths, List<string> outNotEditablePaths, [uei.DefaultValue("StatusQueryOptions.UseCachedIfPossible")] StatusQueryOptions statusQueryOptions = StatusQueryOptions.UseCachedIfPossible)
        {
            if (assetOrMetaFilePaths == null)
                throw new ArgumentNullException(nameof(assetOrMetaFilePaths));
            if (outNotEditablePaths == null)
                throw new ArgumentNullException(nameof(outNotEditablePaths));
            UnityEngine.Profiling.Profiler.BeginSample("AssetDatabase.IsOpenForEdit");
            AssetModificationProcessorInternal.IsOpenForEdit(assetOrMetaFilePaths, outNotEditablePaths, statusQueryOptions);
            UnityEngine.Profiling.Profiler.EndSample();
        }

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Early-return when the path array is null or empty.
  2. Build paths with an explicit fallback: paths ?? Array.Empty<string>().
  3. Validate selection before deriving paths: Selection.objects may be empty.
  4. Log the originating operation when paths come back null to find the upstream gap.

Example fix

// before
AssetDatabase.CanOpenForEdit(selectedPaths, notEditable, StatusQueryOptions.UseCachedIfPossible);

// after
if (selectedPaths == null || selectedPaths.Length == 0) return;
AssetDatabase.CanOpenForEdit(selectedPaths, notEditable, StatusQueryOptions.UseCachedIfPossible);
Defensive patterns

Strategy: validation

Validate before calling

if (assetOrMetaFilePaths == null || assetOrMetaFilePaths.Length == 0) return;

Type guard

static bool HasPaths(string[] p) => p != null && p.Length > 0;

Prevention

When it happens

Trigger: Calling CanOpenForEdit(null, outList). Passing a selection-derived array that came back null when nothing was selected. Forwarding the result of AssetDatabase.GetAssetPath on a null selection.

Common situations: Editor context-menu actions that operate on selected assets but run with empty/null selection. Version-control pre-checks in batch tools. Build hooks verifying editability of generated paths.

Related errors


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