eval
The eval namespace contains compile-time directives to change the evaluation rate of an expression.
They allow you to specify if a specific expression should be evaluated at spawn or evolve, or at a lower update-rate.
They are the script equivalent to changing a node’s 'SimulationState' and 'EvolveRate' properties.
Return type |
Description |
|
|
|
|
|
|
|
|
|
|
|
|
Examples
Sometimes when creating scripts, you want some expressions to be evaluated at evolve, without necessarily making your entire script node run at evolve.
This is often the case when reading things that vary with time, for example the particle age or life-ratio.
The following script will run entirely at spawn time:
float sizeVar = rand(0.5, 1.0);
float t = 1 - self.lifeRatio; // self.lifeRatio evaluates to 0 at spawn
Size = sizeVar * pow(t, 0.5) * 0.1;
And because self.lifeRatio is zero at spawn by definition, the output Size will never change.
Making this script node run at evolve will also make the rand() function run every frame, producing a flickering size.
The solution here is to either split the script into multiple nodes, and use the self.lifeRatio node, which is by default evaluated at evolve, or to keep everything in a single script and use the eval.full() function:
float sizeVar = rand(0.5, 1.0); // evaluated at spawn
float t = 1 - eval.full(self.lifeRatio); // self.lifeRatio will be evaluated every frame
Size = sizeVar * pow(t, 0.5) * 0.1; // sizeVar * 0.1 evaluated at spawn, the rest which depend on 't' at evolve