Variables
Tutorial: How to use variables to create interactive 3d content in Spline
Variables allow you to create reusable values/parameters. They can be applied to many object properties (like Position, Scale, Rotation, etc.) and can be combined with events and actions. This enables you to create highly customized interactions that understand logic.
Some high-level concepts for variables are:
Create variables such as Numbers, Strings, and Booleans
Use Dynamic variables: Time, Counter, Random
Attach variables to object properties and text fields.
Trigger events from variables
Capture object and mouse property changes
By leveraging variables, along with
Variables
Variables are data containers with values that can change. The following variable types are available:
π’ Number
Easily manage numerical data to control and animate objects.
Can be a decimal or a round number, e.g.:
9
or67,123
Usage: alter or adjust any property on your object that uses a number (e.g.: position, rotation, scale, material layer opacity, etc.)
π€ String
Can be any text value, e.g.:
some text
Incorporate text-based variables for labels, messaging or updating the status of your experience.
π Boolean
Toggle between
true
andfalse
states for interactive behavior.With the help of booleans, you can build sophisticated logic into your experience, especially if you combine it with
and .
Dynamic variables
Dynamic variables are changing over time based on specific conditions. These unlock the creation of interactive experiences driven by variables. The following dynamic variable types are available: Time, Counter, Random.
π Time
Harness the flow of time to create dynamic animations and transitions
Itβs defined by a string that can be applied as the content of a Text object.
It has following types: Clock, Timer, Stopwatch
All types have unique property options, listed below
π Clock β Updating time, based on local time or on a specific time zone.
Property | Explanation | Options |
---|---|---|
Format | Change the appearance of the time based on common formatting options. |
|
12/24h | Option to use 24 hours based time. |
|
Time Zone | Show the local time zone or a specific time zone. |
|
β²οΈ Timer β Calculating from a pre-defined time backwards, e.g.: from 30 seconds to 0 seconds
Property | Explanation | Options |
---|---|---|
Format | Change the appearance of the time based on common formatting options. |
|
Value | At what time should the timer/stopwatch start |
|
End Value | If set to |
|
On End | Can be decided if the timer should restart, or end after it reached the end value. |
|
β±οΈ Stopwatch β Calculating from a pre-defined time forward, e.g.: from 0 seconds to 30 seconds.
Property | Explanation | Options |
---|---|---|
Format | Change the appearance of the time based on common formatting options. |
|
Value | At what time should the stopwatch start |
|
End Value | If set to |
|
On End | Can be decided if the stopwatch should restart, or end after it reached the end value. |
|
π’ Counter
The Counter will start counting in seconds with a set interval defined in seconds. It can be great to use it for iterating through dynamic sequences or loops, e.g.: driving an animation with the counter.
Property | Explanation | Options |
---|---|---|
Format | Change the appearance of the time based on common formatting options. |
|
Value | At what time should the counter start |
|
Interval | ||
Step | ||
End Value | If set to |
|
On End | Can be decided if the timer should restart, or end after it reached the end value. |
|
π Random
Random will generate a random value within a set range. With random values create randomness and unpredictability in your project, e.g., mini-game logic and procedural visuals.
Property | Explanation | Options |
---|---|---|
Default value | A default value can be defined for the variable. |
|
Static | Random can be static, or non-static |
|
Interval | If Static is set to No, a new random number will be generated with the set interval defined in seconds |
|
Minimum | The range in which the random numbers should be picked, defining itβs minimum value. |
|
Maximum | The range in which the random numbers should be picked, defines itβs maximum value. |
|
Decimals | Defining the formatting of the random numbers. |
|
Local Storage
Enabling local storage on your variables will allow you to store persistent data on your exported scenes using variables.
Variables Local Storage is a paid feature; youβll need an active Professional or Team subscription to use it.
Try it on the demo: β Bar Chart - Persistent
Enabling Local Storage
Open the variables panel, from the right sidebar.
Find the variable you want to make persistent with local storage.
Press the local storage icon that shows up on hover.
To reset the persistent data of your variables back to their default values using an event trigger you can use the
Events supporting variables
Following Events have access to the
Some high-level concepts for using variables with events and actions:
- A special event that is triggered when a variableβs value changes. Pro tip: use these with the dynamic variables (e.g.: counter) to animate an objectβs property. - An action that allows you to modify variables and object properties. It can be either another referenced variable or can be a custom calculation.
How to use variables
Here is a simple guide to creating variables, assigning them to a cube, and updating it via an event.
Create variables
Open the variable table from the right sidebar, itβs visible when no objects are selected.
Select a variable type, for this exercise select βNumberβ.
Change the number to a specific value in the right column, e.g.:
100
.Double-click the name of the variable βNumberβ, to change its name, name it something like
Initial Position
.Right-click the variable and select βduplicateβ to duplicate it.
Name the duplicate something like
New Position
and adjust itβs value to200
.Done, the variables are ready to be used!
Assign a variable to an object
Create a cube (select it in the top toolbar and click on the viewport).
Select the cube.
Hover any of itβs properties (e.g.: Position X).
Click on the little dot in the upper right corner.
Select the variable to be assigned,
Initial Position
in this case.Done, the object is driven by a variable!
Update variables with events and actions
Variables can be updated with all sorts of events and actions. Here is a simple example of updating the variable via a mouse click.
Select the cube.
Add an event in the right sidebar at the events section.
Open the event βStartβ by clicking on it.
Change the event type in the top dropdown to βMouse Downβ.
Add an action βSet Variableβ.
Expand the action by clicking on the β>β icon.
Select the variable you would like to change, it should be
Initial Position
in this exercise.In the βToβ section there is an βAdd expressionβ field, here is the place where you can define what should be the selected variable updated to when the event is performed. Click in the field and select the initially created
New Position
variable.Enter Play mode and click on the cube.
Congrats! You have created your first variable update via a Mouse Down Event.
Best practices and troubleshooting
Keep It Simple: Start with a few variables and build complexity as you gain confidence.
Test and Iterate: Experiment with different variable values to find the perfect balance for your spline project.
Variable Not Updating?: Ensure that the Variable Change events and Set Variable actions are correctly configured and referencing the right variable. Also, check the formula being used.
Unexpected Behavior: Double-check your logic to identify any discrepancies in your variable usage.