Unity-Technologies/UnityCsReference · error · ArgumentNullException

Value cannot be null. (Parameter 'playModeViews')

Error message

Value cannot be null. (Parameter 'playModeViews')

What it means

Thrown by FrameDebugger.GetAllAvailablePlayModeViews when the playModeViews list passed by reference is null. The method populates the caller-supplied list with all open PlayModeView windows (main view plus any additional windows). It requires a pre-allocated list because it uses the list as both input (to avoid duplicates) and output buffer.

Source

Thrown at Editor/Mono/PerformanceTools/FrameDebugger.cs:302

        private void HandleEnablingFrameDebugger()
        {
            if (Event.current.type != EventType.Repaint)
                return;

            m_EnablingWaitCounter++;
            if (m_EnablingWaitCounter == k_NeedToRepaintFrames)
            {
                FrameDebuggerEvent[] descs = FrameDebuggerUtility.GetFrameEvents();
                m_TreeView = new FrameDebuggerTreeView(descs, m_TreeViewState, this, new Rect(50, 50, 500, 100));
                m_FrameEventsHash = FrameDebuggerUtility.eventsHash;
                ChangeFrameEventLimit(FrameDebuggerUtility.count);
            }
        }

        int GetAllAvailablePlayModeViews(ref List<PlayModeView> playModeViews)
        {
            if (playModeViews == null)
                throw new ArgumentNullException(nameof(playModeViews));

            var mainPlaymodeView = PlayModeView.GetMainPlayModeView();
            if (mainPlaymodeView != null)
                playModeViews.Add(mainPlaymodeView);

            foreach (var playModeView in PlayModeView.GetAllPlayModeViewWindows())
            {
                if (playModeView != null && !playModeViews.Contains(playModeView))
                    playModeViews.Add(playModeView);
            }

            return playModeViews.Count;
        }

        internal bool GetFirstAvailablePlayModeView(out PlayModeView playModeView)
        {
            playModeView = null;

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Initialize the list before passing it: var views = new List<PlayModeView>(); GetAllAvailablePlayModeViews(ref views);
  2. If this is a field, ensure it is assigned in the constructor or field initializer before any method that calls GetAllAvailablePlayModeViews.
  3. Add a null-coalescing initializer at the call site: playModeViews ??= new List<PlayModeView>();

Example fix

// before
GetAllAvailablePlayModeViews(ref m_Views); // m_Views is null

// after
m_Views ??= new List<PlayModeView>();
GetAllAvailablePlayModeViews(ref m_Views);
Defensive patterns

Strategy: validation

Validate before calling

playModeViews ??= new List<PlayModeView>();
GetAllAvailablePlayModeViews(ref playModeViews);

Prevention

When it happens

Trigger: Calling GetAllAvailablePlayModeViews(ref someList) where someList is null. This is an internal method used during frame debugger enable/refresh cycles, so the error surfaces when the frame debugger's tree view refresh encounters an uninitialized list reference.

Common situations: Frame debugger window initialization; editor extension code that queries play mode views; refactoring that changes the list initialization order so the method is called before the list field is constructed.

Related errors


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