Data Binding: Quick Tip for Updating Data every frame
I’m on a quest to make games in Rive! I’m finding out it’s more difficult and has made me have to learn trigonometric functions… more on that later. But for now, one of the things that many game engines have is a “do this every frame” function where all the game-y stuff is put inside of that function. Examples: checking what direction you’re pointing, where enemies are, firing a weapon, etc.
Rive’s data binding allows us to drive properties with data - but how might we change data over time, similarly to how in a game engine you would say “Move +10 in the Y axis every frame”? How can we use Data to animate an object?
Step 1: Make an event (ex: “frameUpdate”), and add a listener for it called “frameUpdate”:
Make sure the artboard is the target for the listener, otherwise your event might not show up in the options.
Add a View Model in the “Data” tab, and a number property for the data you’d like to change over time. Example: “y position”
Select the object you’d like to update every frame, and bind the property to the data you just created. In my case, I’m going to bind this square’s Y position property to the “y” number data in the View Model.
Create a looping timeline, and make it only 1 frame long. Then add a “report event” keyframe on your frameUpdate event.
In the state machine, set the looping timeline to play on entry (or trigger it with an input if you’d like).
CleanShot 2025-03-15 at 22.14.21.mp4
If you press play now, nothing will happen, except the object will go to whatever the position of the data is set to. In my case, it’s zero on the Y position. But you can slide the data up and down and see how it works:We’re almost there. Let’s add a calculate function in the converters under Data. Set it to add 10 (or whatever number you want).
Now all that’s left is to change the data over time. Go back to your listener on the event frameUpdate, and instead of having it change an input, let’s have it change the View Model data we just set up:
8. Make sure your Artboard has the View Model instance selected, then run it! Your object should be animating from the data, and updating every frame!