This event works similarly to onUpdate, except that it is used for drawing custom ImGui UI. It gets triggered on every frame that the game runs, thus is framerate dependent.
Use this event with caution, as it is triggered continuously once the game is launched.
Trying to draw ImGui UI outside this callback is prohibited
Usage Example
Render an ImGui window at anytime:
init.lua
registerForEvent('onDraw', function()if ImGui.Begin('Window Title', ImGuiWindowFlags.AlwaysAutoResize) then ImGui.Text('Hello World!')end ImGui.End()end)
Advanced Example
Render an ImGui window when the player is sprinting:
This example use observers. Check the documentation for further information on its usage.
init.lua
-- set initial switchisSprinting =false-- onInitregisterForEvent('onInit', function()-- observe Sprint OnEnter stateObserve('SprintEvents', 'OnEnter', function(stateContext,scriptInterface) isSprinting =trueend)-- observe Sprint OnExit stateObserve('SprintEvents', 'OnExit', function(stateContext,scriptInterface) isSprinting =false-- reset switchend)end)-- onDrawregisterForEvent('onDraw', function()-- bail early if not sprintingifnot isSprinting thenreturnend-- draw windowif ImGui.Begin('Notification', ImGuiWindowFlags.AlwaysAutoResize) then ImGui.Text('Nice sprint!')end ImGui.End()end)