Unity-Technologies/UnityCsReference · error · ArgumentNullException

renderPickingCallback

Error message

renderPickingCallback

What it means

RegisterRenderPickingCallback throws ArgumentNullException when the supplied callback delegate is null. The callback is stored in a static list (s_RenderPickingCallbacks) and invoked during Scene view picking passes to determine which custom objects are pickable.

Source

Thrown at Editor/Mono/Handles/HandleUtility.cs:2235

        // Repaint the current view
        public static void Repaint()
        {
            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)

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Pass a non-null RenderPickingCallback delegate.
  2. Register the callback in OnEnable and unregister the same delegate instance in OnDisable.

Example fix

// before
HandleUtility.RegisterRenderPickingCallback(maybeNullCallback);
// after
if (myCallback != null)
    HandleUtility.RegisterRenderPickingCallback(myCallback);
Defensive patterns

Strategy: validation

Validate before calling

if (renderPickingCallback == null)
    return;
HandleUtility.RegisterRenderPickingCallback(renderPickingCallback);

Prevention

When it happens

Trigger: Calling HandleUtility.RegisterRenderPickingCallback(null) or passing a callback variable that was never assigned.

Common situations: An editor tool that registers picking callbacks conditionally, passing a delegate field that is null when the condition was not met, or a partial initialization path.

Related errors


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