Calling the Engine API and Project Script

    In the Scene Script you can call the engine API and other project scripts, and with this feature we can

    • Query and traverse the nodes in the scene to get or modify node data
    • Call functions related to the engine components on the node to finish the job

    First, add a scene field to the contributions property of package.json, the value of which is the path to a script file, relative to the extension package directory. Example:

    Create a new scene.ts in the src directory and write the following code.

    unload - the function that fires when the module is unloaded

    methods - methods defined inside the module that can be used to respond to external messages

    Next, we will demonstrate how the scene script calls the engine API by rotating the main camera.

    In the above code, we have defined a rotateCamera method that rotates the main camera 10 degrees around the Y axis every time it is executed.

    In other extension scripts, we can call the function with the following code.

    The properties of ExecuteSceneScriptMethodOptions are defined as follows:

    • method: the method defined in scene.ts
    • args: arguments, optional