Nested ViewModel property access from script inputs

Summary

When a script input is bound to a container ViewModel that contains nested ViewModel properties, those nested ViewModels are reachable via getViewModel() or dot access — but the returned PropertyViewModel exposes no typed property accessors (getNumber, getString, getBoolean, getColor, etc.). This forces every nested ViewModel that needs property access to be declared as its own top-level script input, which scales poorly as the number of nested VMs grows.

Concrete example (what I'd like to write)

lua

type MyNode = {
    -- A container VM holding N nested VMs of the same type
    -- (vmItem1 .. vmItemN inside VmContainer).
    vmContainer: Input<Data.VmContainer>,
}

function init(self: MyNode, context: Context): boolean
    -- Hoped-for: drill into a nested VM via dot or :getViewModel,
    -- get a usable handle, set a primitive property on it.
    local item1 = self.vmContainer.vmItem1   -- or :getViewModel("vmItem1")
    item1.inputValue.value = "hello"

    return true
end

What actually happens

Tested in Rive Luau scripting (current stable). Findings, all confirmed with focused test scripts using pcall guards:

  1. Field-chain access (self.vmContainer.vmItem1) returns a non-nil value at runtime, but typeof(...) reports userdata and (value :: any).inputValue is nil. The static type system also reports PropertyViewModel for the field, blocking compilation without an :: any cast.

  2. Method-based access (self.vmContainer:getViewModel("vmItem1")) also returns a non-nil userdata value. Calling any typed accessor on it (:getString("inputValue"), :getNumber("...")) raises:

    getString is not a valid method of PropertyViewModel
    getNumber is not a valid method of PropertyViewModel
  3. The same limitation applies to nested VMs reached via context:viewModel():getViewModel("childVm") — the returned object is also a PropertyViewModel without typed accessors.

The documentation at https://rive.app/docs/scripting/data-binding shows vmi:getViewModel('dateViewModel') and stops there — it never demonstrates reading or writing properties through the returned reference. Without that demonstration, the docs are technically consistent with the runtime, but the omission gives the strong impression that nested access works the way most data-binding systems work (chained property access). It doesn't.

What this costs

For any script that needs to read or write properties across a pool of similar nested VMs, the leaf VMs cannot share a single container script input — each leaf must become its own Input<Data.LeafType> declaration. A container with 16 leaves costs 16 script inputs instead of 1. Multiple such pools per script compound that count quickly.

Each individual input requires:

  • A separate late() slot in the script's return table

  • A separate binding in the Rive editor's script-input panel

  • A separate corresponding ViewModel instance in the Data panel

On top of that, the Data panel already has the nested structure (the container VM does contain the leaf VMs as nested properties) — the script side is forced to flatten it, then mentally re-nest it when reasoning about the data model.

Proposed behaviour

Either of these would resolve the issue:

Option A — return typed VMs from nested access on a script-input ViewModel:

lua

local item1: Data.VmItem = self.vmContainer.vmItem1
item1.inputValue.value = "hello"   -- works

Option B — give PropertyViewModel the same typed accessors as the root VM:

lua

local item1 = self.vmContainer:getViewModel("vmItem1")
local val = item1:getString("inputValue")
val.value = "hello"   -- works

Option A is the cleaner outcome (full type safety throughout the tree). Option B is the smaller surface change and matches the documented "use getViewModel" guidance.

Workaround in use today

Declare each leaf VM as its own top-level script input. The technique works but scales 1× per leaf, and the bookkeeping (late() entries, editor bindings, array assembly in init) becomes a significant portion of the editor-side setup cost as the number of nested VMs grows.

Why I'm asking

The current limitation seems incidental rather than fundamental — getViewModel already returns a non-nil reference, the runtime knows the type of the field from the editor's VM declaration, and primitive-property access on a directly- bound nested VM already works (as shown in the docs for Input<Data.Character> where Character is nested under Main). Closing the gap to nested-VM access through a parent input would remove the only real friction with using nested ViewModels for organisational clarity.