# RegisterCallback

> Adds an event handler to the instance.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.UIElements](/engine/6000.5/script-reference/unityengine/uielements.md)
* **Assembly:** UnityEngine.UIElementsModule

## RegisterCallback\<T>(EventCallback\<T>, TrickleDown)

Adds an event handler to the instance.

```csharp
public void RegisterCallback<TEventType>(EventCallback<TEventType> callback, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase<TEventType>, new()
```

### Parameters

**** (\[EventCallback\<T>]\(/engine/6000.5/script-reference/unityengine/uielements/eventcallback1)): The event handler to add. If the handler is null, this method throws an exception.**** (\[TrickleDown]\(/engine/6000.5/script-reference/unityengine/uielements/trickledown)): By default, this callback is called during the BubbleUp phase. Pass `TrickleDown.TrickleDown` to call this callback during the TrickleDown phase.

### Remarks

If the event handler is already registered for the same phase (either TrickleDown or BubbleUp), this method has no effect.

Refer to the [Handle event callbacks and value changes](/engine/6000.5/manual/uitoolkits/uielements/uie-events/handling.md) manual page for more information and examples.

Additional Resources: [PropagationPhase](/engine/6000.5/script-reference/unityengine/uielements/propagationphase.md)

## RegisterCallback\<T, U>(EventCallback\<T, T>, T, TrickleDown)

Adds an event handler to the instance.

```csharp
public void RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType> callback, TUserArgsType userArgs, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase<TEventType>, new()
```

### Parameters

**** (\[EventCallback\<T, T>]\(/engine/6000.5/script-reference/unityengine/uielements/eventcallback1)): The event handler to add. If the handler is null, this method throws an exception.**** (T): Data to pass to the callback. Use this argument to avoid closing on local variables.**** (\[TrickleDown]\(/engine/6000.5/script-reference/unityengine/uielements/trickledown)): By default, this callback is called during the BubbleUp phase. Pass `TrickleDown.TrickleDown` to call this callback during the TrickleDown phase.

### Remarks

If the event handler is already registered for the same phase (either TrickleDown or BubbleUp), this method has no effect.

Refer to the [Handle event callbacks and value changes](/engine/6000.5/manual/uitoolkits/uielements/uie-events/handling.md) manual page for more information and examples.

Additional Resources: [PropagationPhase](/engine/6000.5/script-reference/unityengine/uielements/propagationphase.md)

### Examples

```csharp
using UnityEngine;
using UnityEngine.UIElements;

[RequireComponent(typeof(UIDocument))]
public class RegisterCallbackExample : MonoBehaviour
{
    void OnEnable()
    {
        var myClickableLabel = new Label("Click me");

        myClickableLabel.RegisterCallback<PointerDownEvent, string>((ev, userArg) =>
        {
            Debug.Log("Hello from " + userArg);
        }, gameObject.name);

        GetComponent<UIDocument>().rootVisualElement.Add(myClickableLabel);
    }
}
```

## RegisterCallback\<T>(EventCallback\<T>, CallbackOptions)

Adds an event handler to the instance.

```csharp
public void RegisterCallback<TEventType>(EventCallback<TEventType> callback, CallbackOptions callbackOptions) where TEventType : EventBase<TEventType>, new()
```

### Parameters

**** (\[EventCallback\<T>]\(/engine/6000.5/script-reference/unityengine/uielements/eventcallback1)): The event handler to add. If the handler is null, this method throws an exception.**** (\[CallbackOptions]\(/engine/6000.5/script-reference/unityengine/uielements/callbackoptions)): Extra properties to set for the callback.

### Remarks

If the event handler is already registered for the same phase (either TrickleDown or BubbleUp), this method has no effect.

Refer to the [Handle event callbacks and value changes](/engine/6000.5/manual/uitoolkits/uielements/uie-events/handling.md) manual page for more information and examples.

Additional Resources: [PropagationPhase](/engine/6000.5/script-reference/unityengine/uielements/propagationphase.md)

## RegisterCallback\<T, U>(EventCallback\<T, T>, T, CallbackOptions)

Adds an event handler to the instance.

```csharp
public void RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType> callback, TUserArgsType userArgs, CallbackOptions callbackOptions) where TEventType : EventBase<TEventType>, new()
```

### Parameters

**** (\[EventCallback\<T, T>]\(/engine/6000.5/script-reference/unityengine/uielements/eventcallback1)): The event handler to add. If the handler is null, this method throws an exception.**** (T): Data to pass to the callback. Use this argument to avoid closing on local variables.**** (\[CallbackOptions]\(/engine/6000.5/script-reference/unityengine/uielements/callbackoptions)): Extra properties to set for the callback.

### Remarks

If the event handler is already registered for the same phase (either TrickleDown or BubbleUp), this method has no effect.

Refer to the [Handle event callbacks and value changes](/engine/6000.5/manual/uitoolkits/uielements/uie-events/handling.md) manual page for more information and examples.

Additional Resources: [PropagationPhase](/engine/6000.5/script-reference/unityengine/uielements/propagationphase.md)
