Skip to main content
Context is an object provided to scripted nodes during initialization (via the init function). It serves as a bridge between your script and the Rive runtime, giving you access to:
  • Update scheduling — Request that your node be updated on the next frame.
  • Data (ViewModels) — Access the ViewModel data context bound to the node or the root artboard.
  • Assets — Retrieve named assets (images, blobs, and audio) that have been added to the Rive file.

Methods

markNeedsUpdate

Marks the object as needing an update on the next frame. Call this when something has changed (e.g., from a listener callback) and you need the runtime to re-invoke your node’s update function. Note: Calls to markNeedsUpdate from inside update() are ignored. Use it from init(), advance(), listener callbacks, or event handlers instead.

viewModel

Returns the ViewModel bound to the node’s immediate data context. This is the most common way to read data-bound properties from a script.

rootViewModel

Returns the ViewModel bound to the root artboard’s data context. Useful when you need to access top-level data from a deeply nested node.

dataContext

Returns the data context provided to this node.

image

Returns an image asset by name, or nil if not found. The returned Image can be drawn via drawImage. See also ImageSampler. Check out Scripting demos to see a working example.

blob

Returns a Blob (raw binary data) asset by name, or nil if not found. Useful for loading custom data files embedded in the Rive file.

audio

Returns an AudioSource asset by name. The returned source can be played using the global Audio API.

canvas

Create a 2D canvas for Rive Renderer drawing. Use beginFrame/endFrame inside drawCanvas to render. The descriptor is optional. Omitting it (or passing width/height of 0) creates a deferred canvas with no backing texture — useful in layout scripts that don’t know their size at init. Call canvas:resize(w, h) once the real size is known. While deferred, canvas.image is nil and width/height report 0; calling beginFrame() raises an error pointing to resize(). Check canvas.width > 0 to gate work.

gpuCanvas

Create a GPU canvas — a 1× presentation target. Render to it via canvas:beginRenderPass(...). For MSAA, allocate the multisampled color and depth textures yourself with GPUTexture.new({ sampleCount = N, renderTarget = true }) and pass them in the descriptor. The descriptor is optional. Omitting it (or passing width/height of 0) creates a deferred canvas with no backing texture — useful in layout scripts that don’t know their size at init. Call canvas:resize(w, h) once the real size is known. While deferred, width/height report 0 and calling colorView() raises an error pointing to resize(). Check canvas.width > 0 to gate work.

features

Query GPU capabilities. Returns a table of supported features and limits for the current backend.

shader

Get a compiled shader by asset name (the name as added in the editor, with no “.wgsl” extension). Returns a Shader ready for use in GPUPipeline.new(), or nil if the named shader is not found.

decodeImage

Decode compressed image data (PNG, JPEG, WebP) into premultiplied RGBA8 pixels. Returns a Promise that resolves with a DecodedImage table. Use with await() inside async(), or chain with :andThen().