Chapters:

A world expression is a cuboid-shaped object, which executes arbitrary expressions (scripts) at the specified distance and the frame rate. By default, the expressions are executed at the same frame rate as the main application.

Notice

An expression is executed only when its bounding box is in the viewing frustum or when the camera is positioned within this bounding box.

By using world expressions, you can attach a script to an object in the scene. For this, such object must be assigned as a child node to the world expression.
In this case, the child nodes will inherit transformations (if any) of the world expression.

Notice

The child nodes are transformed relative to the pivot point of the world expression node.

If there are nested world expression nodes, the child node of the last world expression in the hierarchy will inherit transformations of all the parent world expression nodes.

For example, by using the world expression, you can transform objects in the scene, turn on and off sounds with the distance, turn on and off NPC behavior, attach objects to the camera (e.g. drops of the rain on the camera) and so on.

ObjectMeshDynamic nodes added as children to the nested WorldExpression nodes

Creating World Expression

Attaching World Expression Script

There are two ways to attach a world expression script via UnigineEditor:

It can be implemented directly in UnigineEditor in the Parameters window -> Expression tab -> Source field. The source code must wrapped with the curly braces{} as they define the world expression scope.

It can be attached as a script file in the Parameters window -> Expression tab -> File field. In this case, the script file should be included in the world expression scope in the Parameters window -> Expression tab -> Source field. The curly braces{} are also required:

In this case, the
my_expression.h contains the following code:

Source code (UnigineScript)

log.message("WorldExpression is updated\n");

Notice

In the script file, the source code must not be wrapped with curly braces {}.

Implementing Script

The script itself can be implemented as a simple sequence of functions' calls or as a set of functions and classes. See the examples here.

Notice

It is recommended to implement simple scripts.

Inter-Script Communication

Script Functions

Besides functions of the UnigineScript library, there is also a set of internal functions that are available within the world expression script. The list of such functions with descriptions and examples can be found here.

Setting World Expression Parameters

You can adjust the following parameters of the world expression in the Expression tab:

Size

A size of the bounding box of the world expression along the X, Y and Z axes.

If the bounding box is in the viewing frustum or the camera is positioned within the bounding box, the expression is executed.

If the child node of the world expression node gets outside the viewing frustum, but the bounding box is still in the viewing frustum (or the camera is positioned within the bounding box), the playback of the transformation sequence will not stop.

Offset

An offset of the center of the world expression's bounding box along the X, Y and Z axes.

Distance

A distance at which the expression is not executed.

IFps

A constant frame duration (inverse FPS, 1/FPS) used to execute the expression. If 0 is set, the expression is executed at the same frame rate as the main application.

File

A path to a file with a world expression script to be executed. The path is relative to the data directory. This file should be included in the world expression scope in the Source field. This field is optional as the world expression script can be implemented directly via the UnigineEditor interface (see the description of the Source field below).

Notice

If the script file is changed, it should be refreshed via UnigineEditor: click
to the right of the
File field.

Source

A source code of a world expression script. This field can contain:

Direct implementation of the world expression script.

The #include directive that loads the script file specified in the File field (see the description above).

Notice

In both cases, the curly braces {} must wrap the code in the field.

Deleting World Expression

To delete the world expression via UnigineEditor, select the world expression node in the nodes hierarchy list and press Delete.

Last update: 2018-06-04

We use cookies to ensure that we give you the best experience on our website. Click here for more information.