Unity-Technologies/UnityCsReference · error · InvalidOperationException
{RegisterRenderPickingCallback} cannot be called during pick
Error message
{RegisterRenderPickingCallback} cannot be called during picking rendering What it means
RegisterRenderPickingCallback throws InvalidOperationException when called while a picking render pass is in progress (s_InPickingRendering is true). This guard prevents the static callback list from being modified mid-iteration, which would cause collection corruption or skipped callbacks.
Source
Thrown at Editor/Mono/Handles/HandleUtility.cs:2237
{
Internal_Repaint();
}
public delegate UnityObject ResolvePickingCallback(int localPickingIndex);
public delegate UnityObject ResolvePickingWithWorldPositionCallback(int localPickingIndex, Vector3 worldPos, float depth);
public delegate RenderPickingResult RenderPickingCallback(in RenderPickingArgs args);
[AutoStaticsCleanupOnCodeReload]
private static readonly List<RenderPickingCallback> s_RenderPickingCallbacks = new();
[AutoStaticsCleanupOnCodeReload]
private static readonly List<(int PickingIndexBegin, int PickingIndexEnd, ResolvePickingCallback Resolver, ResolvePickingWithWorldPositionCallback ResolverWithWorldPos)> s_RenderPickingResults = new();
public static bool RegisterRenderPickingCallback(RenderPickingCallback renderPickingCallback)
{
if (renderPickingCallback == null)
throw new ArgumentNullException(nameof(renderPickingCallback));
if (s_InPickingRendering)
throw new InvalidOperationException($"{nameof(RegisterRenderPickingCallback)} cannot be called during picking rendering");
foreach (var registered in s_RenderPickingCallbacks)
{
if (registered == renderPickingCallback)
return false;
}
s_RenderPickingCallbacks.Add(renderPickingCallback);
return true;
}
public static bool UnregisterRenderPickingCallback(RenderPickingCallback renderPickingCallback)
{
if (renderPickingCallback == null)
throw new ArgumentNullException(nameof(renderPickingCallback));
if (s_InPickingRendering)
throw new InvalidOperationException($"{nameof(UnregisterRenderPickingCallback)} cannot be called during picking rendering");
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Move callback registration to OnEnable, OnSceneGui (before repaint), or another non-rendering lifecycle hook.
- If dynamic registration is needed during rendering, defer it with EditorApplication.delayCall until the render pass completes.
Example fix
// before
RenderPickingResult OnRenderPicking(in RenderPickingArgs args)
{
HandleUtility.RegisterRenderPickingCallback(ExtraPicking);
...
}
// after
RenderPickingResult OnRenderPicking(in RenderPickingArgs args)
{
EditorApplication.delayCall += () => HandleUtility.RegisterRenderPickingCallback(ExtraPicking);
...
} Defensive patterns
Strategy: validation
Validate before calling
// s_InPickingRendering is private and cannot be checked directly.
// Instead, ensure registration happens only outside render passes:
void OnEnable() {
HandleUtility.RegisterRenderPickingCallback(OnRenderPicking);
} Try / catch
try { HandleUtility.RegisterRenderPickingCallback(cb); }
catch (InvalidOperationException) {
EditorApplication.delayCall += () => HandleUtility.RegisterRenderPickingCallback(cb);
} Prevention
- Register callbacks in OnEnable, never inside a render-picking callback body.
- If deferred registration is unavoidable, use EditorApplication.delayCall to push it outside the render pass.
When it happens
Trigger: Calling RegisterRenderPickingCallback from inside another RenderPickingCallback, or from any code path that executes during the picking render loop.
Common situations: An editor tool that dynamically registers sub-callbacks from within its own picking callback, creating a re-entrant registration; or SceneGUI code that registers during repaint.
Related errors
- {UnregisterRenderPickingCallback} cannot be called during pi
- ScriptableBakedReflectionSystemWrapper
- Not a valid handle, has it been released already?
- Get GetPickingIncludeExcludeList is obsolete, use GetPicking
- renderPickingCallback
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/72e92be5b915f79c.
Report an issue: GitHub.