Skip to main content
Version: latest - a1.156.0 ⚖️

🖼️ Canvas

Canvas is an entity which you can draw onto it.

👪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

TypeNameDefaultDescription
booleanis_visibletrueWhether to draw it on screen
Colorclear_colorColor.TRANSPARENTColor to clear with (background color)
floatauto_repaint_rate-1Rate to auto repaint (call Update event), pass 0 for every frame, -1 to disable
booleanshould_clear_before_updatetrueWhether to clear with Clear Color before updates
booleanauto_resizetrueAuto resize with screen's size
integerwidth0If not using auto_resize
integerheight0If not using auto_resize
Vector2Dscreen_positionVector2D(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
ReturnsNameDescription
table of Base EntityGetAllReturns a table containing all Entities of the class this is called on
Base EntityGetByIndexReturns a specific Entity of this class at an index
integerGetCountReturns how many Entities of this class exist
table of tableGetInheritedClassesGets a list of all directly inherited classes from this Class created with the Inheriting System
iteratorGetPairsReturns an iterator with all Entities of this class to be used with pairs()
table or nilGetParentClassGets the parent class if this Class was created with the Inheriting System
tableInheritInherits this class with the Inheriting System
booleanIsChildOfGets if this Class is child of another class if this Class was created with the Inheriting System
functionSubscribeSubscribes to an Event for all entities of this Class
functionSubscribeRemoteSubscribes to a custom event called from server
UnsubscribeUnsubscribes 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
ReturnsNameDescription
BroadcastRemoteEventCalls a custom remote event directly on this entity to all Players
BroadcastRemoteInRadiusEventCalls a custom remote event directly on this entity to all Players in a radius
CallRemoteEventCalls a custom remote event directly on this entity to a specific Player
CallRemoteEventCalls a custom remote event directly on this entity
CallRemotePlayersEventCalls a custom remote event directly on this entity to a list of Players
DestroyDestroys this Entity
FinishSpawnFinish the spawning process and send the entity to clients if it was spawned with a deferred spawn_mode
table of stringGetAllValuesKeysGets a list of all values keys
tableGetClassGets the class of this entity
integerGetIDGets the universal network ID of this Entity (same on both client and server)
anyGetValueGets a Value stored on this Entity at the given key
booleanHasAuthorityGets if the local context has authority over this Entity (true if spawned by the client, false if spawned by the server)
booleanIsARecursively checks if this entity is inherited from a Class
booleanIsBeingDestroyedReturns true if this Entity is being destroyed
booleanIsSpawnedGets if this Entity finished spawning
booleanIsValidReturns true if this Entity is valid (i.e. wasn't destroyed and points to a valid Entity)
SetSpawnModeOverrides when this Entity finishes spawning, from the Constructor of an Inherited Class
SetValueSets a Value in this Entity
functionSubscribeSubscribes to an Event on this specific entity
functionSubscribeRemoteSubscribes to a custom event called from server on this specific entity
UnsubscribeUnsubscribes all callbacks from this Event in this Entity within this Package, or only the callback passed
ReturnsNameDescription
ClearClear the Canvas with a specific Color
DrawBoxDraws an unfilled box on the Canvas
DrawLineDraws a line on the Canvas
DrawMaterialDraws a Material on the Canvas
DrawMaterialFromSceneCaptureDraws a SceneCapture on the Canvas
DrawMaterialFromWebUIDraws a WebUI on the Canvas
DrawPolygonDraws a N-Polygon on the Canvas
DrawRectDraws a filled Rect on the Canvas
DrawTextDraws a Text on the Canvas
DrawTextureDraws a Texture on the Canvas
Vector2DGetSizeGets the Canvas Size
RepaintForces the repaint
ResizeResizes the Canvas if not using auto_resize
SetAutoRepaintRateSets the repaint rate
SetAutoResizeSets if the canvas should auto resize to screen size
SetScreenPositionSets the Canvas Screen Position offset
SetVisibilitySets if it's visible on screen

Optimal

Clear​

Clear the Canvas with a specific Color
my_canvas:Clear(clear_color)

Parameters

TypeParameterDefaultDescription
Colorclear_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 inside Update event
my_canvas:DrawBox(screen_position, screen_size, thickness, render_color?, blend_mode?)

Parameters

TypeParameterDefaultDescription
Vector2Dscreen_position Required parameter Position on the Canvas, in pixels
Vector2Dscreen_size Required parameter Size on the Canvas, in pixels
floatthickness Required parameter Line thickness
Colorrender_color?Color.WHITE
Color to tint the drawing with
BlendModeblend_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 inside Update event
my_canvas:DrawLine(screen_position_a, screen_position_b, thickness, render_color, blend_mode?)

Parameters

TypeParameterDefaultDescription
Vector2Dscreen_position_a Required parameter Start position of the line, in pixels
Vector2Dscreen_position_b Required parameter End position of the line, in pixels
floatthickness Required parameter Line thickness
Colorrender_color Required parameter Color to tint the drawing with
BlendModeblend_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 inside Update event

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

TypeParameterDefaultDescription
Material Referencematerial_path Required parameter The Material asset to use
Vector2Dscreen_position Required parameter Position on the Canvas, in pixels
Vector2Dscreen_size Required parameter Size on the Canvas, in pixels
Vector2Dcoordinate_position Required parameter Top-left UV coordinate of the source to draw (0 to 1)
Vector2Dcoordinate_size?Vector2D(1, 1)
UV size of the source to draw (0 to 1), use (1, 1) for the whole source
floatrotation?0
Rotation in degrees
Vector2Dpivot_point?Vector2D(0.5, 0.5)
Pivot of the rotation, relative to the drawing size (0.5, 0.5 is the center)
BlendModeblend_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 inside Update event

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

TypeParameterDefaultDescription
SceneCapturescenecapture_entity Required parameter The SceneCapture to draw
Vector2Dscreen_position Required parameter Position on the Canvas, in pixels
Vector2Dscreen_size Required parameter Size on the Canvas, in pixels
Vector2Dcoordinate_position Required parameter Top-left UV coordinate of the source to draw (0 to 1)
Vector2Dcoordinate_size?Vector2D(1, 1)
UV size of the source to draw (0 to 1), use (1, 1) for the whole source
floatrotation?0
Rotation in degrees
Vector2Dpivot_point?Vector2D(0.5, 0.5)
Pivot of the rotation, relative to the drawing size (0.5, 0.5 is the center)
BlendModeblend_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 inside Update event

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

TypeParameterDefaultDescription
WebUIwebui_entity Required parameter The WebUI to draw
Vector2Dscreen_position Required parameter Position on the Canvas, in pixels
Vector2Dscreen_size Required parameter Size on the Canvas, in pixels
Vector2Dcoordinate_position Required parameter Top-left UV coordinate of the source to draw (0 to 1)
Vector2Dcoordinate_size?Vector2D(1, 1)
UV size of the source to draw (0 to 1), use (1, 1) for the whole source
floatrotation?0
Rotation in degrees
Vector2Dpivot_point?Vector2D(0.5, 0.5)
Pivot of the rotation, relative to the drawing size (0.5, 0.5 is the center)
BlendModeblend_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 inside Update event
my_canvas:DrawPolygon(texture_path, screen_position, radius?, number_of_sides?, render_color?, blend_mode?)

Parameters

TypeParameterDefaultDescription
Image Pathtexture_path Required parameter Pass empty to use default white Texture
Vector2Dscreen_position Required parameter Position on the Canvas, in pixels
Vector2Dradius?Vector2D(1, 1)
Radius of the polygon on each axis, in pixels
integernumber_of_sides?3
How many sides the polygon has
Colorrender_color?Color.WHITE
Color to tint the drawing with
BlendModeblend_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 inside Update event
my_canvas:DrawRect(texture_path, screen_position, screen_size, render_color?, blend_mode?)

Parameters

TypeParameterDefaultDescription
Image Pathtexture_path Required parameter Pass empty to use default white Texture
Vector2Dscreen_position Required parameter Position on the Canvas, in pixels
Vector2Dscreen_size Required parameter Size on the Canvas, in pixels
Colorrender_color?Color.WHITE
Color to tint the drawing with
BlendModeblend_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 inside Update event

Shadow and Outline won't work properly with Transparent clear_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

TypeParameterDefaultDescription
stringtext Required parameter The text to draw
Vector2Dscreen_position Required parameter Position on the Canvas, in pixels
FontTypefont_type?FontType.Roboto
Font to use
integerfont_size?12
Font size
Colortext_color?Color.WHITE
Color of the text
floatkerning?0
Extra spacing between characters
booleancenter_x?false
Whether to center the text horizontally on the position
booleancenter_y?false
Whether to center the text vertically on the position
Colorshadow_color?Color.TRANSPARENT
Color of the text shadow, transparent to disable it
Vector2Dshadow_offset?Vector2D(1, 1)
Offset of the shadow, in pixels
booleanoutlined?false
Whether to draw an outline around the text
Coloroutline_color?Color.BLACK
Color of the outline

Moderate

DrawTexture​

Draws a Texture on the Canvas

This method can only be called from inside Update event
my_canvas:DrawTexture(texture_path, screen_position, screen_size, coordinate_position, coordinate_size?, render_color?, blend_mode?, rotation?, pivot_point?)

Parameters

TypeParameterDefaultDescription
Image Pathtexture_path Required parameter The image to draw
Vector2Dscreen_position Required parameter Position on the Canvas, in pixels
Vector2Dscreen_size Required parameter Size on the Canvas, in pixels
Vector2Dcoordinate_position Required parameter Top-left UV coordinate of the source to draw (0 to 1)
Vector2Dcoordinate_size?Vector2D(1, 1)
UV size of the source to draw (0 to 1), use (1, 1) for the whole source
Colorrender_color?Color.WHITE
Color to tint the drawing with
BlendModeblend_mode?BlendMode.AlphaBlend
AlphaBlend is recommended for textures with transparency. Otherwise you may use Opaque.
floatrotation?0
Rotation in degrees
Vector2Dpivot_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

TypeDescription
Vector2Dthe 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

TypeParameterDefaultDescription
integerwidth Required parameter Width in pixels
integerheight 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

TypeParameterDefaultDescription
floatauto_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

TypeParameterDefaultDescription
booleanauto_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

TypeParameterDefaultDescription
Vector2Dscreen_position Required parameter The new Canvas Screen Position offset

Optimal

SetVisibility​

Sets if it's visible on screen
my_canvas:SetVisibility(visible)

Parameters

TypeParameterDefaultDescription
booleanvisible 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
NameDescription
ClassRegisterTriggered when a new Class is registered with the Inheriting System
DestroyTriggered when an Entity is destroyed
SpawnTriggered when an Entity is spawned/created
ValueChangeTriggered when an Entity has a value changed with :SetValue()
NameDescription
UpdateCalled 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)

Arguments

TypeArgumentDescription
CanvasselfThe Canvas that triggered the event
integerwidthWidth in pixels
integerheightHeight in pixels