Scripts are used to control the game’s progress by manipulating specific objects under the right conditions, and thus realizing logic that is not possible or difficult to achieve by relying on self-contained objects.
Distinction between script types
Block and code scripts
We provide two ways to edit scripts: block scripts and code.
Block scripts are more intuitive and easy to use with visual blocks for script editing. But the complexity rises faster and the script is more difficult to maintain when writing complex logic.
Code Scripting Script editing using code is more free and maintainable when dealing with complex logic.
Server and Client Scripts
Regardless of block or code, scripts need to differentiate between running platforms: server or client.
Server scripts can only use events and interfaces supported by the server, and the same applies to clients.
Events that can only be run under the server platform
Static Scripts
A static script refers to a script that is automatically attached to the global entity by default.
It is a property of a script file and can be enabled or disabled on a client/server script.
For Primitive (graph-based) scripts, when selected in the FE Project, you will find a “Static” checkbox in the Inspector panel.
For code-based scripts, simply add the static
keyword before the graph
declaration, like this:
static graph Test {
}
go
After editing the code, remember to go back to FE and save.
In the Global module of FE, you can browse all static scripts.
Using static scripts makes visual scripting easier. You can focus on editing them in the script editor without manually opening the global module and attaching them.
There is also an extra benefit for code scripts—a convenient syntax sugar available for static scripts:
// GlobalManager.fcg
static graph GlobalManager {
func MyFunc1() {
}
func MyFunc2() {
}
}
// In another file
import "./GlobalManager.fcg" as GlobalManager
graph Test {
event OnAwake() {
GlobalManager.MyFunc1() // Call static script functions directly via dot notation
GlobalManager.MyFunc2() // Equivalent to globalEntity<GlobalManager>.MyFunc2(), saves some typing
}
}
go
Because static scripts are automatically attached to the global entity, their functions can be directly called by using the script name, without needing to reference globalEntity
.
Note: A script attached to the global entity is not automatically considered a static script.
If you want to access GlobalManager.MyFunc2
directly without specifying the entity, you must manually set the script as static.
Create a script
Right click in the editable assets area to create a new script
Select New when mounting the script:
New scripts created in this way will be automatically mounted on the corresponding entity and will be automatically named with the name of the current entity.
When creating a script, you need to select/configure the category of the script:
- server script or client script, which affects the events and interfaces that can be used by this script.
- block script or code script, this affects how the script is edited.
Editing Scripts
Double click on the script file to open it for editing, for block and code scripts please refer to the following documentation:
Mounting Scripts
Mounting to a Module:
Mount to object:
Select the object you want to add script to, and choose Add Script in its inspector panel:

Again, you can select an existing script or create a new one.
Adding scripts using scripts:
We provide an interface that can mount scripts for entities:
Adding scripts:
It is recommended that you use the Existing Scripts interface to confirm that the entity already has the same script before adding it.
Uninstalling Scripts
To statically uninstall a script before starting the game, simply find the mount and click the minus sign:
To uninstall the script dynamically after the game has started, use the Delete Script interface:
Again, we recommend confirming that the entity does indeed mount the script to be deleted before deleting:
Managing Script Files
If you create a new script when adding a script, it will automatically create a new ECA folder under the Assets folder to hold the new script:
We also recommend that you use folders to categorize the scripts you create
Delete
Scripts can be deleted by using the shortcut Delete, or by right-clicking on the script in the asset:
For entities that already have this script mounted, an error with a yellow exclamation point will appear:
Copy
Using the shortcut keys Ctrl+C, Ctrl+V, or using the right-click menu, you can copy the script. The copied script name is the name of the original script plus (X), and X is the number of copies - 1.
Rename
Using the shortcut F2, or using the context menu, you can rename the script.
Scripts cannot be renamed, naming a script with the same name as an existing script will result in an error and cancel the renaming: