View Models
There are three ways that a script can gain access to a View Model and its properties:- Accessing View Models through Context
- Data binding a View Model as an input
- Data binding view model properties to inputs
Context
Theinit lifecycle function includes a context parameter that gives you access
to your view models. This allows you to read values (strings, enums, lists, etc.), set values,
fire triggers, listen for triggers, and subscribe to value changes.
In addition to view models, Context gives you access to named assets and update scheduling.
View Models as Inputs
You can create a Script Input that can be bound to a view model. This allows you to read values (strings, enums, lists, etc.), set values, fire triggers, listen for triggers, and subscribe to value changes.Binding Inputs
If you only need to read, not set view model properties, you can data bind view model property values to script inputs. For more information see Data Binding Inputs.Nested View Models
To reference a nested view model, usegetViewModel.
Reading and Setting Properties
The following methods allow you to reference view model properties:Listening for Property Changes
Add a Listener
UseaddListener to listen for triggers or changes to view model properties.