Drawingtool
Based on game build 714014 | Last updated: 2026-03-03
Overview
DrawingTool enables an entity (typically a tool or character) to locate a nearby drawable entity and retrieve its visual representation (image, atlas, background image, etc.) for rendering. It works in conjunction with the inventoryitem and drawable components to support dynamic visual customization. The component handles the logic of identifying a valid target within range and extracting the necessary asset identifiers for the draw operation.
Usage example
local inst = CreateEntity()
inst:AddComponent("drawingtool")
inst:AddComponent("inventoryitem")
inst.components.drawingtool:SetOnDrawFn(function(downer, target, image, src, atlas, bgimage, bgatlas)
print("Drawing", image, "on", target)
end)
-- When performing the draw action:
local image, target, atlas, bgimage, bgatlas = inst.components.drawingtool:GetImageToDraw(targetEntity, inst)
if image then
inst.components.drawingtool:Draw(targetEntity, image, src, atlas, bgimage, bgatlas)
end
Dependencies & tags
Components used: inventoryitem, drawable
Tags:
TODRAW_MUST_TAGS = {"_inventoryitem"}— Entities must have this tag to be considered.TODRAW_CANT_TAGS = {"INLIMBO", "notdrawable"}— Entities with these tags are excluded.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
ondrawfn | function (optional) | nil | Callback fired when a successful draw operation completes. Signature: fn(downer, target, image, src, atlas, bgimage, bgatlas). |
Main functions
SetOnDrawFn(fn)
- Description: Sets a custom callback function to be invoked after a successful
Drawcall. - Parameters:
fn(function ornil) — Function to be called with parameters(downer, target, image, src, atlas, bgimage, bgatlas). Set tonilto clear. - Returns: Nothing.
GetImageToDraw(target, doer)
- Description: Searches for a drawable entity near
targetand extracts its visual asset identifiers. Must be called beforeDraw. - Parameters:
target(Entity ornil) — The original target entity (e.g., the user of the tool or the main interaction point).
doer(Entity) — The entity performing the action (used for context-sensitive overrides). - Returns:
image(string ornil) — Image name to draw.ent(Entity ornil) — The selected drawable entity (target of drawing).atlas(string ornil) — Atlas name for the image.bgimage(string ornil) — Optional background image name.bgatlas(string ornil) — Optional background atlas name.
- Error states: Returns
nilif no suitable entity is found, or iftargetisnil.
Draw(target, image, src, atlas, bgimage, bgatlas)
- Description: Applies the provided visual assets to the
targetentity using itsdrawablecomponent. Triggers theondrawfncallback if set. - Parameters:
target(Entity ornil) — Entity to receive the drawn assets.
image(string ornil) — Image name.
src(string ornil) — Source context (not used internally, passed toOnDrawn).
atlas(string ornil) — Atlas name for the image.
bgimage(string ornil) — Background image name.
bgatlas(string ornil) — Background atlas name. - Returns: Nothing.
- Error states: No-op if
targetisnilor lacks thedrawablecomponent.
Events & listeners
- Listens to: None (uses
inst:ListenForEventinternally in other components). - Pushes: None (draw operation is synchronous and event-driven via callbacks).