# RegisterRenderPickingCallback(RenderPickingCallback)

> Registers a callback to invoke when Unity renders for picking.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.7/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

```csharp
public static bool RegisterRenderPickingCallback(HandleUtility.RenderPickingCallback renderPickingCallback)
```

### Parameters

**** (\[RenderPickingCallback]\(/engine/6000.7/script-reference/unityeditor/handleutility/renderpickingcallback)): The delegate object to register to the callback.

### Returns

| Type                                                          | Description                                                                     |
| ------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if the registration succeeds. False if the callback is already registered. |

### Remarks

Use this callback to render custom geometries on top of the existing scene objects to the picking render texture, so that the GameObjects represented by custom geometries can be picked.

Each rendering must write out a [Vector4](/engine/6000.7/script-reference/unityengine/vector4.md)-typed `selectionId` to the picking render texture. The `selectionId` is encoded from the [pickingIndex](/engine/6000.7/script-reference/unityeditor/renderpickingargs/pickingindex.md) passed into the callback through the [RenderPickingArgs](/engine/6000.7/script-reference/unityeditor/renderpickingargs.md) struct using the function [HandleUtility.EncodeSelectionId](/engine/6000.7/script-reference/unityeditor/handleutility/encodeselectionid.md). You can render multiple SelectionIds in one callback if they are encoded sequentially from incrementing the `pickingIndex`, and you return the total number of rendered picking indices when returning from the callback.

Most Unity shaders have a "ScenePickingPass" pass that can be used for the rendering. Use [Material.FindPass](/engine/6000.7/script-reference/unityengine/material/findpass.md) with the pass name "ScenePickingPass" to find the index of the shader pass from a [Material](/engine/6000.7/script-reference/unityengine/material.md), and use this pass index when you call APIs such as [Material.SetPass](/engine/6000.7/script-reference/unityengine/material/setpass.md). Note that you can only use render functions that are considered to take effect immediately, such as [Graphics.DrawMeshNow](/engine/6000.7/script-reference/unityengine/graphics/drawmeshnow.md) and [Graphics.DrawProceduralNow](/engine/6000.7/script-reference/unityengine/graphics/drawproceduralnow.md) (instead of their non-immediate counterparts [Graphics.DrawMesh](/engine/6000.7/script-reference/unityengine/graphics/drawmesh.md) and [Graphics.DrawProcedural](/engine/6000.7/script-reference/unityengine/graphics/drawprocedural.md)). The alternative is to record your rendering to a [CommandBuffer](/engine/6000.7/script-reference/unityengine/rendering/commandbuffer.md) object, and call [Graphics.ExecuteCommandBuffer](/engine/6000.7/script-reference/unityengine/graphics/executecommandbuffer.md) after the recording.

The picking render texture has already been bound as the active render texture when it entered the callback. You can change the active render texture during the callback, but you must restore the active render texture before exiting the callback.

Your rendering must respect the ignore and filter GameObject sets passed to the callback through the [RenderPickingArgs](/engine/6000.7/script-reference/unityeditor/renderpickingargs.md) struct argument to determine under the current context what should be rendered. Refer to [RenderPickingArgs](/engine/6000.7/script-reference/unityeditor/renderpickingargs.md) for more information.

After rendering, return a [RenderPickingResult](/engine/6000.7/script-reference/unityeditor/renderpickingresult.md) struct with the number of picking indices you used, and another callback function to invoke to resolve the picking index to a GameObject reference to be selected once the user ends up clicking on the rendered pixel under the mouse. If nothing needs to render, you can return the struct with [renderedPickingIndexCount](/engine/6000.7/script-reference/unityeditor/renderpickingresult/renderedpickingindexcount.md) being 0, or simply [RenderPickingResult.NoOperation](/engine/6000.7/script-reference/unityeditor/renderpickingresult/nooperation.md). Refer to [RenderPickingResult](/engine/6000.7/script-reference/unityeditor/renderpickingresult.md) for more information.

The method throws `InvalidOperationException` if you try to call it inside render picking callbacks.

Additional Resources: [UnregisterRenderPickingCallback](/engine/6000.7/script-reference/unityeditor/handleutility/unregisterrenderpickingcallback.md).
