🖼️ Canvas
Canvas is an entity which you can draw onto it.
Client OnlyAPI Source
👪Inheritance
This class shares methods and events from Base Entity.
🎒 Examples
Client/Index.lua
-- Spawns a Canvas
local my_canvas = Canvas(
true,
Color.TRANSPARENT,
0,
true
)
-- Subscribes for Update, we can only Draw inside this event
my_canvas:Subscribe("Update", function(self, width, height)
-- Draws a Text in the middle of the screen
self:DrawText("Hello World!", Vector2D(width / 2, height / 2))
-- Draws a red line Horizontally
self:DrawLine(Vector2D(0, height / 2), Vector2D(width, height / 2), 10, Color.RED)
end)
-- Forces the canvas to repaint, this will make it trigger the Update event
my_canvas:Repaint()
-- Applies the Canvas as the material of a (client side) StaticMesh
local my_mesh = StaticMesh(Vector(0, 0, 100), Rotator(), "nanos-world::SM_Cube")
my_mesh:SetMaterialFromCanvas(my_canvas)
tip
You can use the output Texture from a Canvas with :SetMaterialFromCanvas() method!
🛠 Constructors
Default Constructor
No description provided
local my_canvas = Canvas(is_visible?, clear_color?, auto_repaint_rate?, should_clear_before_update?, auto_resize?, width?, height?, screen_position?)
Parameters
| Type | Name | Default | Description |
|---|---|---|---|
| boolean | is_visible | true | Whether to draw it on screen |
| Color | clear_color | Color.TRANSPARENT | Color to clear with (background color) |
| float | auto_repaint_rate | -1 | Rate to auto repaint (call Update event), pass 0 for every frame, -1 to disable |
| boolean | should_clear_before_update | true | Whether to clear with Clear Color before updates |
| boolean | auto_resize | true | Auto resize with screen's size |
| integer | width | 0 | If not using auto_resize |
| integer | height | 0 | If not using auto_resize |
| Vector2D | screen_position | Vector2D(0, 0) | If not using auto_resize, offset when drawing to screen |
🗿 Static Functions
Inherited Entity Static Functions
Canvas inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/entity
Base Entityscripting-reference/classes/base-classes/entity
| Returns | Name | Description | |
|---|---|---|---|
| table of Base Entity | GetAll | Returns a table containing all Entities of the class this is called on | |
| Base Entity | GetByIndex | Returns a specific Entity of this class at an index | |
| integer | GetCount | Returns how many Entities of this class exist | |
| table of table | GetInheritedClasses | Gets a list of all directly inherited classes from this Class created with the Inheriting System | |
| iterator | GetPairs | Returns an iterator with all Entities of this class to be used with pairs() | |
| table or nil | GetParentClass | Gets the parent class if this Class was created with the Inheriting System | |
| table | Inherit | Inherits this class with the Inheriting System | |
| boolean | IsChildOf | Gets if this Class is child of another class if this Class was created with the Inheriting System | |
| function | Subscribe | Subscribes to an Event for all entities of this Class | |
| function | SubscribeRemote | Subscribes to a custom event called from server | |
Unsubscribe | Unsubscribes all callbacks from this Event in this Class within this Package, or only the callback passed |
This class doesn't have own static functions.
🦠 Functions
Inherited Entity Functions
Canvas inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/entity
Base Entityscripting-reference/classes/base-classes/entity
| Returns | Name | Description | |
|---|---|---|---|
BroadcastRemoteEvent | Calls a custom remote event directly on this entity to all Players | ||
BroadcastRemoteInRadiusEvent | Calls a custom remote event directly on this entity to all Players in a radius | ||
CallRemoteEvent | Calls a custom remote event directly on this entity to a specific Player | ||
CallRemoteEvent | Calls a custom remote event directly on this entity | ||
CallRemotePlayersEvent | Calls a custom remote event directly on this entity to a list of Players | ||
Destroy | Destroys this Entity | ||
FinishSpawn | Finish the spawning process and send the entity to clients if it was spawned with a deferred spawn_mode | ||
| table of string | GetAllValuesKeys | Gets a list of all values keys | |
| table | GetClass | Gets the class of this entity | |
| integer | GetID | Gets the universal network ID of this Entity (same on both client and server) | |
| any | GetValue | Gets a Value stored on this Entity at the given key | |
| boolean | HasAuthority | Gets if the local context has authority over this Entity (true if spawned by the client, false if spawned by the server) | |
| boolean | IsA | Recursively checks if this entity is inherited from a Class | |
| boolean | IsBeingDestroyed | Returns true if this Entity is being destroyed | |
| boolean | IsSpawned | Gets if this Entity finished spawning | |
| boolean | IsValid | Returns true if this Entity is valid (i.e. wasn't destroyed and points to a valid Entity) | |
SetSpawnMode | Overrides when this Entity finishes spawning, from the Constructor of an Inherited Class | ||
SetValue | Sets a Value in this Entity | ||
| function | Subscribe | Subscribes to an Event on this specific entity | |
| function | SubscribeRemote | Subscribes to a custom event called from server on this specific entity | |
Unsubscribe | Unsubscribes all callbacks from this Event in this Entity within this Package, or only the callback passed |
| Returns | Name | Description | |
|---|---|---|---|
Clear | Clear the Canvas with a specific Color | ||
DrawBox | Draws an unfilled box on the Canvas | ||
DrawLine | Draws a line on the Canvas | ||
DrawMaterial | Draws a Material on the Canvas | ||
DrawMaterialFromSceneCapture | Draws a SceneCapture on the Canvas | ||
DrawMaterialFromWebUI | Draws a WebUI on the Canvas | ||
DrawPolygon | Draws a N-Polygon on the Canvas | ||
DrawRect | Draws a filled Rect on the Canvas | ||
DrawText | Draws a Text on the Canvas | ||
DrawTexture | Draws a Texture on the Canvas | ||
| Vector2D | GetSize | Gets the Canvas Size | |
Repaint | Forces the repaint | ||
Resize | Resizes the Canvas if not using auto_resize | ||
SetAutoRepaintRate | Sets the repaint rate | ||
SetAutoResize | Sets if the canvas should auto resize to screen size | ||
SetScreenPosition | Sets the Canvas Screen Position offset | ||
SetVisibility | Sets if it's visible on screen |
Optimal

Clear
Clear the Canvas with a specific Color
my_canvas:Clear(clear_color)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Color | clear_color | Required parameter | The color to fill the Canvas with |
Moderate

DrawBox
Draws an unfilled box on the Canvas
This method can only be called from insideUpdateevent
my_canvas:DrawBox(screen_position, screen_size, thickness, render_color?, blend_mode?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | screen_position | Required parameter | Position on the Canvas, in pixels |
| Vector2D | screen_size | Required parameter | Size on the Canvas, in pixels |
| float | thickness | Required parameter | Line thickness |
| Color | render_color? | Color.WHITE | Color to tint the drawing with |
| BlendMode | blend_mode? | BlendMode.Opaque | How it blends with what is already drawn |
Moderate

DrawLine
Draws a line on the Canvas
This method can only be called from insideUpdateevent
my_canvas:DrawLine(screen_position_a, screen_position_b, thickness, render_color, blend_mode?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | screen_position_a | Required parameter | Start position of the line, in pixels |
| Vector2D | screen_position_b | Required parameter | End position of the line, in pixels |
| float | thickness | Required parameter | Line thickness |
| Color | render_color | Required parameter | Color to tint the drawing with |
| BlendMode | blend_mode? | BlendMode.Opaque | How it blends with what is already drawn |
Moderate

DrawMaterial
Draws a Material on the Canvas
This method can only be called from insideUpdateevent
Note: Due how Unreal handles Render Targets, drawing material on Canvas result on a weird translucent effect. Hope in the future to be improved.
my_canvas:DrawMaterial(material_path, screen_position, screen_size, coordinate_position, coordinate_size?, rotation?, pivot_point?, blend_mode?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Material Reference | material_path | Required parameter | The Material asset to use |
| Vector2D | screen_position | Required parameter | Position on the Canvas, in pixels |
| Vector2D | screen_size | Required parameter | Size on the Canvas, in pixels |
| Vector2D | coordinate_position | Required parameter | Top-left UV coordinate of the source to draw (0 to 1) |
| Vector2D | coordinate_size? | Vector2D(1, 1) | UV size of the source to draw (0 to 1), use (1, 1) for the whole source |
| float | rotation? | 0 | Rotation in degrees |
| Vector2D | pivot_point? | Vector2D(0.5, 0.5) | Pivot of the rotation, relative to the drawing size (0.5, 0.5 is the center) |
| BlendMode | blend_mode? | BlendMode.Opaque | How it blends with what is already drawn |
Moderate

DrawMaterialFromSceneCapture
Draws a SceneCapture on the Canvas
This method can only be called from insideUpdateevent
Note: Due how Unreal handles Render Targets, drawing material on Canvas result on a weird translucent effect. Hope in the future to be improved.
my_canvas:DrawMaterialFromSceneCapture(scenecapture_entity, screen_position, screen_size, coordinate_position, coordinate_size?, rotation?, pivot_point?, blend_mode?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| SceneCapture | scenecapture_entity | Required parameter | The SceneCapture to draw |
| Vector2D | screen_position | Required parameter | Position on the Canvas, in pixels |
| Vector2D | screen_size | Required parameter | Size on the Canvas, in pixels |
| Vector2D | coordinate_position | Required parameter | Top-left UV coordinate of the source to draw (0 to 1) |
| Vector2D | coordinate_size? | Vector2D(1, 1) | UV size of the source to draw (0 to 1), use (1, 1) for the whole source |
| float | rotation? | 0 | Rotation in degrees |
| Vector2D | pivot_point? | Vector2D(0.5, 0.5) | Pivot of the rotation, relative to the drawing size (0.5, 0.5 is the center) |
| BlendMode | blend_mode? | BlendMode.Opaque | How it blends with what is already drawn |
Moderate

DrawMaterialFromWebUI
Draws a WebUI on the Canvas
This method can only be called from insideUpdateevent
Note: Due how Unreal handles Render Targets, drawing material on Canvas result on a weird translucent effect. Hope in the future to be improved.
my_canvas:DrawMaterialFromWebUI(webui_entity, screen_position, screen_size, coordinate_position, coordinate_size?, rotation?, pivot_point?, blend_mode?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| WebUI | webui_entity | Required parameter | The WebUI to draw |
| Vector2D | screen_position | Required parameter | Position on the Canvas, in pixels |
| Vector2D | screen_size | Required parameter | Size on the Canvas, in pixels |
| Vector2D | coordinate_position | Required parameter | Top-left UV coordinate of the source to draw (0 to 1) |
| Vector2D | coordinate_size? | Vector2D(1, 1) | UV size of the source to draw (0 to 1), use (1, 1) for the whole source |
| float | rotation? | 0 | Rotation in degrees |
| Vector2D | pivot_point? | Vector2D(0.5, 0.5) | Pivot of the rotation, relative to the drawing size (0.5, 0.5 is the center) |
| BlendMode | blend_mode? | BlendMode.Opaque | How it blends with what is already drawn |
Moderate

DrawPolygon
Draws a N-Polygon on the Canvas
This method can only be called from insideUpdateevent
my_canvas:DrawPolygon(texture_path, screen_position, radius?, number_of_sides?, render_color?, blend_mode?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Image Path | texture_path | Required parameter | Pass empty to use default white Texture |
| Vector2D | screen_position | Required parameter | Position on the Canvas, in pixels |
| Vector2D | radius? | Vector2D(1, 1) | Radius of the polygon on each axis, in pixels |
| integer | number_of_sides? | 3 | How many sides the polygon has |
| Color | render_color? | Color.WHITE | Color to tint the drawing with |
| BlendMode | blend_mode? | BlendMode.Opaque | How it blends with what is already drawn |
Moderate

DrawRect
Draws a fille Rect on the Canvas
This method can only be called from insideUpdateevent
my_canvas:DrawRect(texture_path, screen_position, screen_size, render_color?, blend_mode?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Image Path | texture_path | Required parameter | Pass empty to use default white Texture |
| Vector2D | screen_position | Required parameter | Position on the Canvas, in pixels |
| Vector2D | screen_size | Required parameter | Size on the Canvas, in pixels |
| Color | render_color? | Color.WHITE | Color to tint the drawing with |
| BlendMode | blend_mode? | BlendMode.Opaque | How it blends with what is already drawn |
Moderate

DrawText
Draws a Text on the Canvas
This method can only be called from insideUpdateevent
Shadow and Outline won't work properly with Transparentclear_color
my_canvas:DrawText(text, screen_position, font_type?, font_size?, text_color?, kerning?, center_x?, center_y?, shadow_color?, shadow_offset?, outlined?, outline_color?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | text | Required parameter | The text to draw |
| Vector2D | screen_position | Required parameter | Position on the Canvas, in pixels |
| FontType | font_type? | FontType.Roboto | Font to use |
| integer | font_size? | 12 | Font size |
| Color | text_color? | Color.WHITE | Color of the text |
| float | kerning? | 0 | Extra spacing between characters |
| boolean | center_x? | false | Whether to center the text horizontally on the position |
| boolean | center_y? | false | Whether to center the text vertically on the position |
| Color | shadow_color? | Color.TRANSPARENT | Color of the text shadow, transparent to disable it |
| Vector2D | shadow_offset? | Vector2D(1, 1) | Offset of the shadow, in pixels |
| boolean | outlined? | false | Whether to draw an outline around the text |
| Color | outline_color? | Color.BLACK | Color of the outline |
Moderate

DrawTexture
Draws a Texture on the Canvas
This method can only be called from insideUpdateevent
my_canvas:DrawTexture(texture_path, screen_position, screen_size, coordinate_position, coordinate_size?, render_color?, blend_mode?, rotation?, pivot_point?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Image Path | texture_path | Required parameter | The image to draw |
| Vector2D | screen_position | Required parameter | Position on the Canvas, in pixels |
| Vector2D | screen_size | Required parameter | Size on the Canvas, in pixels |
| Vector2D | coordinate_position | Required parameter | Top-left UV coordinate of the source to draw (0 to 1) |
| Vector2D | coordinate_size? | Vector2D(1, 1) | UV size of the source to draw (0 to 1), use (1, 1) for the whole source |
| Color | render_color? | Color.WHITE | Color to tint the drawing with |
| BlendMode | blend_mode? | BlendMode.AlphaBlend | AlphaBlend is recommended for textures with transparency. Otherwise you may use Opaque. |
| float | rotation? | 0 | Rotation in degrees |
| Vector2D | pivot_point? | Vector2D(0.5, 0.5) | Pivot of the rotation, relative to the drawing size (0.5, 0.5 is the center) |
Optimal

GetSize
Gets the Canvas Size
local size = my_canvas:GetSize()
Returns
| Type | Description |
|---|---|
| Vector2D | the current size |
Moderate

Repaint
Forces the repaint, this will trigger Update event
my_canvas:Repaint()
Moderate

Resize
Resizes the Canvas if not using auto_resize
my_canvas:Resize(width, height)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | width | Required parameter | Width in pixels |
| integer | height | Required parameter | Height in pixels |
Optimal

SetAutoRepaintRate
Sets it to -1 to stop auto repainting or 0 to repaint every frame
my_canvas:SetAutoRepaintRate(auto_repaint_rate)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| float | auto_repaint_rate | Required parameter | Repaint interval in seconds, 0 to repaint every frame or -1 to stop auto repainting |
Optimal

SetAutoResize
Sets if the canvas should auto resize to screen size
my_canvas:SetAutoResize(auto_resize)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| boolean | auto_resize | Required parameter | Whether the canvas should auto resize to screen size |
Optimal

SetScreenPosition
Sets the Canvas Screen Position offset
my_canvas:SetScreenPosition(screen_position)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | screen_position | Required parameter | The new Canvas Screen Position offset |
Optimal

SetVisibility
Sets if it's visible on screen
my_canvas:SetVisibility(visible)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| boolean | visible | Required parameter | Whether it's visible on screen |
🚀 Events
Inherited Entity Events
Canvas inherits from Base Entity Class, sharing it's events:
Base Entityscripting-reference/classes/base-classes/entity
Base Entityscripting-reference/classes/base-classes/entity
| Name | Description | |
|---|---|---|
ClassRegister | Triggered when a new Class is registered with the Inheriting System | |
Destroy | Triggered when an Entity is destroyed | |
Spawn | Triggered when an Entity is spawned/created | |
ValueChange | Triggered when an Entity has a value changed with :SetValue() |
| Name | Description | |
|---|---|---|
Update | Called when the Canvas needs to be painted You can only call :Draw...() methods from inside this event |

Update
Called when the Canvas needs to be painted
You can only call:Draw...()methods from inside this event
Canvas.Subscribe("Update", function(self, width, height)
-- Update was called
end)

