Skip to main content
Content 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.
function init(self: MyNode, context: Context): boolean
    self.context = context
    -- Access a ViewModel property and listen for changes
    local vm = context:viewModel()
    if vm then
        local name = vm:getString("name")
        if name then
            name:addListener(function()
                -- Re-trigger update when the data changes
                if self.context then
                    self.context:markNeedsUpdate()
                end
            end)
        end
    end
    return true
end

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.
function init(self: MyNode, context: Context): boolean
  local vmi = context:viewModel()
  if vmi then
    local cannon = vmi:getTrigger('cannon')
  end

  return true
end

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.
function init(self: MyNode, context: Context): boolean
  local vmi = context:rootViewModel()
  if vmi then
    local cannon = vmi:getTrigger('cannon')
  end

  return true
end

dataContext

Returns the data context provided to this node.
function init(self: MyNode, context: Context): boolean
  local dc = context:dataContext()
  if dc then
     local parentDC = dc:parent()
     local vm = dc:viewModel()
  end

  return true
end

image

Returns an image asset by name, or nil if not found. The returned image can be drawn via drawImage.

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.