Converter Script ignored on Export
Kindly read the first comment as it has the issue isolated.
————————————————
Hello
I am building an interactive tool to help my students understand animation spacing.
All is working well, I only needed to animate the interpolation for q range converter between two timelines to make sure the “follow path” constrain follows the cursor correctly. I used the converter script for that.
All works well in the Rive Editor, however when exported, the converter script animated values seem to be ignored and revert to default values.
This is the behavior in Rive Editor, graph follow cursor correctly:
RiveEditor.movThis is the behavior on export riv, (graph doesn’t follow the cursor correctly)
Export.mov
I tried to analyze the exported file, the animated viewmodel inputs that are used to drive the converter script are actually getting updated correctly.
but the converter script is somehow ignoring them.
Feel free to check the Rive file in action on this link.
This is the converter code, animated between two timelines using “property group”
-- Define the script's data and inputs.
type MyConverter = {
-- These will appear in the Rive editor's script inputs panel
x1: Input<number>,
y1: Input<number>,
x2: Input<number>,
y2: Input<number>,
}
type DataInputs = DataValueNumber
type DataOutput = DataValueNumber
-- Called once when the script initializes.
function init(self: MyConverter, context: Context): boolean
return true
end
-- Mathematical cubic bezier calculation
local function calculateCubicBezier(
targetX: number,
x1: number,
y1: number,
x2: number,
y2: number
): number
if targetX <= 0 then
return 0
end
if targetX >= 1 then
return 1
end
local lower: number = 0
local upper: number = 1
local t: number = targetX
for i = 1, 20 do
local currentX: number = 3 * (1 - t) ^ 2 * t * x1
+ 3 * (1 - t) * t ^ 2 * x2
+ t ^ 3
if math.abs(currentX - targetX) < 0.001 then
break
end
if currentX < targetX then
lower = t
else
upper = t
end
t = (upper + lower) / 2
end
local finalY: number = 3 * (1 - t) ^ 2 * t * y1
+ 3 * (1 - t) * t ^ 2 * y2
+ t ^ 3
return finalY
end
-- Converts the value when binding from source to target.
function convert(self: MyConverter, input: DataInputs): DataOutput
local dv: DataValueNumber = DataValue.number()
if input:isNumber() then
local rawValue = (input :: DataValueNumber).value
-- Step 1: Normalize the joystick input (-1 to 1) into a standard percentage (0 to 1)
local normalizedX = (rawValue + 1) / 2
-- Step 2: Apply the bezier curve using the script inputs
-- We cast them as :: number to keep Luau's strict type-checker happy
local adjustedPercentage = calculateCubicBezier(
normalizedX,
self.x1 :: number,
self.y1 :: number,
self.x2 :: number,
self.y2 :: number
)
-- Output to the Follow Path constraint
dv.value = adjustedPercentage
end
return dv
end
-- Converts the value back when binding from target to source.
function reverseConvert(self: MyConverter, input: DataOutput): DataInputs
local dv: DataValueNumber = DataValue.number()
if input:isNumber() then
local pathValue = (input :: DataValueNumber).value
-- Linear reversal
dv.value = (pathValue * 2) - 1
end
return dv
end
-- Return a factory function that Rive uses to build the Converter instance.
return function(): Converter<MyConverter, DataInputs, DataOutput>
return {
init = init,
convert = convert,
reverseConvert = reverseConvert,
-- These are the default values applied when you attach the script.
-- You can overwrite them directly in the Rive UI!
x1 = 0.19,
y1 = 0.54,
x2 = 0.85,
y2 = 0.47,
}
end
And here is the Embed code am using but I don’t think it’s related to this behavior:
<div style="width: 100%; height: 100%; position: relative; display: block;">
<canvas id="rive-rjhc0" style="width: 100%; height: 100%; display: block;"></canvas>
</div>
<script>
// Wait for the DOM and global scripts to be ready
document.addEventListener("DOMContentLoaded", function() {
// Wait for the Rive library from another embed or global script
function checkRiveAndInit() {
if (typeof rive !== 'undefined') {
initRive();
} else {
setTimeout(checkRiveAndInit, 100);
}
}
checkRiveAndInit();
function initRive() {
// Force fetch fresh file to bypass the "corrupt" cached 304 error
const urlWithCacheBuster = 'https://files.michelsalloum.art/Uploads/riv/Ball_Bounce.riv';
// Initialize Rive
const r = new rive.Rive({
src: urlWithCacheBuster,
canvas: document.getElementById('rive-rjhc0'),
autoplay: true,
layout: new rive.Layout({
fit: rive.Fit.FitWidth,
alignment: rive.Alignment.Center,
}),
stateMachines: 'State Machine 1',
artboard: 'Artboard',
isTouchScrollEnabled: false,
autoBind: true, // Critical for Data Binding
onLoad: () => {
r.resizeDrawingSurfaceToCanvas();
// Populate Data Bindings
const vmi = r.viewModelInstance;
if (vmi) {
try {
const prop_test = vmi.number("test");
if (prop_test) prop_test.value = 0;
const prop_flow = vmi.number("flow");
if (prop_flow) prop_flow.value = 1.248612403869629;
const prop_retime = vmi.boolean("retime");
if (prop_retime) prop_retime.value = false;
const prop_pointer = vmi.boolean("pointer");
if (prop_pointer) prop_pointer.value = false;
const prop_blend = vmi.number("blend");
if (prop_blend) prop_blend.value = 0;
} catch (e) {
console.error("Rive Data Binding Error", e);
}
}
},
onError: (err) => {
console.error("Rive Canvas Error:", err);
}
});
// Handle Window Resizing to keep it crisp
window.addEventListener('resize', () => {
if(r) r.resizeDrawingSurfaceToCanvas();
});
}
});
</script>ball_bounce.rev
All the best, and appreciate any insight on this,
Michel.