# onDraw

This event works similarly to [onUpdate](/cyber-engine-tweaks/cet-functions/events/onupdate.md), except that it is used for drawing custom ImGui UI. It gets triggered on every frame that the game runs, thus is framerate dependent.

{% hint style="warning" %}
Use this event with caution, as it is triggered continuously once the game is launched.
{% endhint %}

{% hint style="danger" %}
Trying to draw ImGui UI outside this callback is prohibited
{% endhint %}

## Usage Example

#### Render an ImGui window at anytime:

{% code title="init.lua" %}

```lua
registerForEvent('onDraw', function()

    if ImGui.Begin('Window Title', ImGuiWindowFlags.AlwaysAutoResize) then
        ImGui.Text('Hello World!')
    end
    
    ImGui.End()
    
end)
```

{% endcode %}

## Advanced Example

#### Render an ImGui window when the player is sprinting:

{% hint style="info" %}
This example use [observers](/cyber-engine-tweaks/cet-functions/observers.md). Check the [documentation](/cyber-engine-tweaks/cet-functions/observers.md) for further information on its usage.
{% endhint %}

{% code title="init.lua" %}

```lua
-- set initial switch
isSprinting = false

-- onInit
registerForEvent('onInit', function()
    
    -- observe Sprint OnEnter state
    Observe('SprintEvents', 'OnEnter', function(stateContext, scriptInterface)
        isSprinting = true
    end)
    
    -- observe Sprint OnExit state
    Observe('SprintEvents', 'OnExit', function(stateContext, scriptInterface)
        isSprinting = false -- reset switch
    end)

end)

-- onDraw
registerForEvent('onDraw', function()
    
    -- bail early if not sprinting
    if not isSprinting then
        return
    end
    
    -- draw window
    if ImGui.Begin('Notification', ImGuiWindowFlags.AlwaysAutoResize) then
        ImGui.Text('Nice sprint!')
    end
    
    ImGui.End()
    
end)
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.redmodding.org/cyber-engine-tweaks/cet-functions/events/ondraw.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
