Working with Console
Calling a Console Command from Code#
To call a console command from any of the scripts, you should call engine.console.run().
// For example, to show the onscreen overlay:
engine.console.run("console_onscreen 1");
Console commands (regardless of whether they were typed in the console or called from code) cannot be executed in the middle of the frame. Instead, they are executed in the beginning of the next frame not to interrupt the current rendering process and physics calculations.
Creating a Console Command#
To create a custom console command, you should:
- Implement a function that will be run on the console command call. If you want your console command to take more than one argument, you need to implement a separate function per each number of arguments.
- Call engine.console.addCommand() to add a new command.
In the example below, a new command takes no arguments or one argument:
// a script function to be executed for no arguments input
void console() {
log.message("console_command with no arguments has been called\n");
}
// a script function to be executed for 1 argument input
void console(string arg) {
log.message("console_command with 1 argument has been called\n Argument: %s\n", arg);
}
int init() {
// create a console command
engine.console.addCommand("console_command","console_command description","console");
return 1;
}
To check the result, run the added command:
Unigine~# console_command
console_command with no arguments has been called
Unigine~# console_command arg
console_command with 1 argument has been called
Argument: arg
You can also remove custom console commands via engine.console.removeCommand().
Creating a Console Variable#
Disabling Console#
To disable console (for example, for an application production version), you need to call engine.console.setLock().
// disable the console
engine.console.setLock(1);
The information on this page is valid for UNIGINE 2.20 SDK.