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
- Initialize the list before passing it: var views = new List<PlayModeView>(); GetAllAvailablePlayModeViews(ref views);
- If this is a field, ensure it is assigned in the constructor or field initializer before any method that calls GetAllAvailablePlayModeViews.
- 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
- Initialize list fields in constructors or field initializers before methods that consume them.
- Use null-coalescing assignment (??=) at call sites for ref-list parameters.
- Establish a convention: never pass null collections to ref parameters.
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
- renderPickingCallback
- Value cannot be null. (Parameter 'context')
- Type should derive from PlayModeView
- Value cannot be null. (Parameter 'defines')
- Value cannot be null. (Parameter 'additionalCompilerArgument
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/d3b96360dbadb322.
Report an issue: GitHub.