Construct varset and parameter expressions
In Construct, you can drive parameter values with formulas instead of fixed numbers. A camera's focal length can follow a sine wave for an animated zoom; a mesh's scale can be tied to a varset entry so a single slider changes everything proportionally. The formula language is the same everywhere in Construct CAD⢠â see the expression language reference for the complete syntax.
Pro Tip
When in doubt about a formula, prototype it in the spreadsheet first. Same language, instant feedback, no risk of breaking your scene while you experiment.
What a varset is
A varset is a named bag of variables you can reference from any parameter expression in your Construct scene. The default varset holds entries you create with simple names (speed, tiltAngle); named varsets group related variables (e.g. a lights varset with intensity, color, diameter).
Each entry is either a literal value or a formula. Formulas can reference other varset entries, scene built-ins, and the standard built-in math functions.
Writing an expression
Open the varset panel and add an entry. Click the value field and type:
clamp(time * 0.5, 0.0, 1.0)
The result evaluates each frame. The cell shows the current value; the formula is stored as the source.
See and edit an expression
A parameter that holds an expression shows its computed value in blue. The expression itself is not on the row:
- To see the expression, hold the pointer on the blue value. The tooltip shows it.
- To edit the expression, click the blue value. The expression opens on a line below the parameter, the full width of the row. The blue value updates as you type.
- The line stays open while you type in it. Press Enter or click somewhere else to close it. Your edit is kept.
When you click E to make a value an expression, the line opens for you.
Turn an expression off
Click E on a parameter row to change between a value and an expression. When you turn the expression off, the parameter keeps a value:
- If the expression computed a value, the parameter keeps that value.
- If it did not, for example because you typed nothing, the parameter goes back to the value it had before you turned the expression on.
This is the same for every parameter that has an E button.
Built-in scene variables
Construct always provides these â you don't need to declare them:
| Variable | Type | Meaning |
|---|---|---|
time |
float |
Seconds since playback started |
frame |
int |
Current frame number (zero-based) |
firstFrame |
int |
First frame of the current render range |
lastFrame |
int |
Last frame of the current render range |
fps |
float |
Frames per second |
width |
int |
Render width in pixels |
height |
int |
Render height in pixels |
These are always available in any varset entry or parameter expression.
Cross-referencing other entries
Inside the default varset, reference an entry by its bare name:
speed = 5.0
distance = speed * time
For named varsets, qualify with the varset name:
camera.zoom = 0.5 + sin(time) * 0.3
When you change speed (or any entry an expression depends on), the engine recomputes only the affected entries.
Helper functions
Define a helper function above the expression body:
float bouncedLength(float t) {
float u = fract(t);
return u < 0.5 ? u * 2.0 : (1.0 - u) * 2.0;
}
bouncedLength(time)
This is useful when the same calculation appears in several entries â define it once, call it from each.
Parameter qualifiers
Helper functions accept in, out, inout, and const parameter qualifiers:
float incrementAndReturn(inout float counter) {
counter = counter + 1.0;
return counter;
}
out and inout write back to the caller's name when the argument is an lvalue. The expression language follows GLSL §6.1.1 semantics.
Animation curves
A common pattern is shaping time through a math function to create a curve:
| Effect | Formula |
|---|---|
| Linear from 0 to 1 over 5 s | clamp(time / 5.0, 0.0, 1.0) |
| Smooth ease in/out | smoothstep(0.0, 5.0, time) |
| Sine oscillation, period 2 s | sin(time * 3.14159) |
| Step function, switching at 3 s | step(3.0, time) |
| Random-looking pulse | fract(sin(time * 12.9898) * 43758.5453) |
A focus pull
A camera item has a lens. Its Aperture (f/) row sets the f-number, and its Focus distance row sets where the lens focuses, in millimeters. While the viewport path traces, a camera with an aperture blurs what is out of focus. The raster engines show a frame at the focus distance instead.
To move the focus from a near object to a far one during the first two seconds, give Focus distance this expression:
mix(400.0, 1200.0, smoothstep(0.0, 2.0, time))
Set Aperture (f/) to a low number, for example 2.8, to make the blur easy to see. An f-number of 0 is a pinhole, which has no blur. A focus distance of 0 focuses at the point the camera turns around.
What happens if a formula is wrong
If a formula doesn't parse, type-check, or evaluate, Construct shows a diagnostic next to the entry. The expression value reverts to a safe default (zero or the previous valid value) while you fix it.
Common errors:
| Diagnostic | What it means |
|---|---|
unresolved name 'foo' |
The expression references a name that isn't declared |
expected ')' after function arguments |
Missing or unbalanced parentheses |
division by zero |
A / 0 reached the runtime; switch to IEEE math if you intend inf |
recursive call cycle through user function 'foo' |
A helper function calls itself directly or via another helper |
Performance notes
Construct's expression engine recompiles a graph when you edit the formula text, but updating values via the slider or animation playback is cheap â it reuses the compiled program and just changes inputs.
If your scene has thousands of expressions and the per-frame total exceeds your frame budget, the developer surface can opt into the native (LLVM JIT) backend which is 10â100Ă faster per evaluation. By default, Construct uses the interpreted backend which works on every platform without an LLVM install.
Binding an expression to a transform
You can drive an item's translate, rotate or scale from an expression. When you do, that channel belongs to the expression: the matching T, R or S icon in the viewport dims and stops responding, and if its gizmo was on screen the handles disappear at once.
That is deliberate. An expression is re-evaluated every frame, so it rewrites its channel each time â a drag would be overwritten before you released the mouse, silently. Taking the handles away says so instead of letting you edit something that cannot stick.
The other two channels are unaffected: binding rotation to an expression leaves you free to drag the object around and scale it as usual. To take a channel back, clear its expression and leave a plain number in its place â the icon becomes active again immediately.
See Move, rotate and scale objects for the icons themselves.
See also
- Expression language reference â the full grammar, type system, and built-in catalogue.
- Spreadsheet how-to â same language in a more interactive surface for prototyping formulas.