Lifecycle callbacks
Callbacks are entry points invoked by Rustic. Define only those a behavior needs.
When each callback runs
| Callback | When to use it | Variables |
|---|---|---|
| OnCreate | One-time construction before startup. | None |
| Start | Resolve references and initialize gameplay state. | None |
| OnEnable | Resume when the owner becomes enabled. | None |
| FixedUpdate | Physics and simulation. | dt: fixed-step seconds |
| Update | Input and presentation. | dt: frame seconds |
| OnDisable | Pause when the owner becomes disabled. | None |
| OnDestroy | Release instance resources. | None |
| OnStop | Final play-session cleanup. | None |
Examples in every language
These registration examples include every callback. Replace each body with the logic you need. Follow your language guide to generate the workspace, install its toolchain, attach the script and press Play. External dispatchers receive dt; it is meaningful for update and fixed_update. Physics runs after FixedUpdate, but collision callbacks use explicit Physics subscriptions, dispatched during Update after fixed-step resolution. Touchscreen callbacks and object clicks use Input subscriptions. HTML examples go inside an inline script in a ui/ HTML asset.
Lua 5.4
lua
return {
OnCreate = function() end,
Start = function() end,
OnEnable = function() end,
FixedUpdate = function(dt) end,
Update = function(dt) end,
OnDisable = function() end,
OnDestroy = function() end,
OnStop = function() end,
}JavaScript
javascript
globalThis.behavior = {
OnCreate() {},
Start() {},
OnEnable() {},
FixedUpdate(dt) {},
Update(dt) {},
OnDisable() {},
OnDestroy() {},
OnStop() {},
};Python
python
from rustic import rustic, run
def on_create():
rustic.log("info", "on_create")
def on_start():
rustic.log("info", "on_start")
def on_enable():
rustic.log("info", "on_enable")
def fixed_update(dt):
rustic.log("info", "fixed_update")
def update(dt):
rustic.log("info", "update")
def on_disable():
rustic.log("info", "on_disable")
def on_destroy():
rustic.log("info", "on_destroy")
def on_stop():
rustic.log("info", "on_stop")
run(globals())C++
cpp
#include "rustic.hpp"
int main() {
RusticBehavior behavior;
behavior.on_create = []() { rustic.log("info", "on_create"); };
behavior.on_start = []() { rustic.log("info", "on_start"); };
behavior.on_enable = []() { rustic.log("info", "on_enable"); };
behavior.fixed_update = [](double dt) { (void)dt; rustic.log("info", "fixed_update"); };
behavior.update = [](double dt) { (void)dt; rustic.log("info", "update"); };
behavior.on_disable = []() { rustic.log("info", "on_disable"); };
behavior.on_destroy = []() { rustic.log("info", "on_destroy"); };
behavior.on_stop = []() { rustic.log("info", "on_stop"); };
return rustic_run(behavior);
}C#
csharp
using static Rustic;
Run((callback, dt) => {
switch (callback) {
case "on_create": rustic.log("info", "on_create"); break;
case "on_start": rustic.log("info", "on_start"); break;
case "on_enable": rustic.log("info", "on_enable"); break;
case "fixed_update": rustic.log("info", "fixed_update"); break;
case "update": rustic.log("info", "update"); break;
case "on_disable": rustic.log("info", "on_disable"); break;
case "on_destroy": rustic.log("info", "on_destroy"); break;
case "on_stop": rustic.log("info", "on_stop"); break;
}
});Luau
lua
return {
OnCreate = function() end,
Start = function() end,
OnEnable = function() end,
FixedUpdate = function(dt) end,
Update = function(dt) end,
OnDisable = function() end,
OnDestroy = function() end,
OnStop = function() end,
}C
c
#include "rustic.h"
static void on_create(void) { rustic.log("info", "on_create"); }
static void on_start(void) { rustic.log("info", "on_start"); }
static void on_enable(void) { rustic.log("info", "on_enable"); }
static void fixed_update(double dt) { (void)dt; rustic.log("info", "fixed_update"); }
static void update(double dt) { (void)dt; rustic.log("info", "update"); }
static void on_disable(void) { rustic.log("info", "on_disable"); }
static void on_destroy(void) { rustic.log("info", "on_destroy"); }
static void on_stop(void) { rustic.log("info", "on_stop"); }
int main(void) {
return rustic_run((RusticBehavior){
.on_create = on_create,
.on_start = on_start,
.on_enable = on_enable,
.fixed_update = fixed_update,
.update = update,
.on_disable = on_disable,
.on_destroy = on_destroy,
.on_stop = on_stop,
});
}Java
java
class RusticBehavior extends Rustic {
public static void main(String[] args) throws Exception {
run((callback, dt) -> {
switch (callback) {
case "on_create" -> rustic.log("info", "on_create");
case "on_start" -> rustic.log("info", "on_start");
case "on_enable" -> rustic.log("info", "on_enable");
case "fixed_update" -> rustic.log("info", "fixed_update");
case "update" -> rustic.log("info", "update");
case "on_disable" -> rustic.log("info", "on_disable");
case "on_destroy" -> rustic.log("info", "on_destroy");
case "on_stop" -> rustic.log("info", "on_stop");
}
});
}
}PHP
php
<?php
require __DIR__ . "/rustic.php";
function on_create(): void {
global $rustic;
$rustic->log("info", "on_create");
}
function on_start(): void {
global $rustic;
$rustic->log("info", "on_start");
}
function on_enable(): void {
global $rustic;
$rustic->log("info", "on_enable");
}
function fixed_update(float $dt): void {
global $rustic;
$rustic->log("info", "fixed_update");
}
function update(float $dt): void {
global $rustic;
$rustic->log("info", "update");
}
function on_disable(): void {
global $rustic;
$rustic->log("info", "on_disable");
}
function on_destroy(): void {
global $rustic;
$rustic->log("info", "on_destroy");
}
function on_stop(): void {
global $rustic;
$rustic->log("info", "on_stop");
}
rustic_run([
"on_create" => "on_create",
"on_start" => "on_start",
"on_enable" => "on_enable",
"fixed_update" => "fixed_update",
"update" => "update",
"on_disable" => "on_disable",
"on_destroy" => "on_destroy",
"on_stop" => "on_stop",
]);HTML / inline JS
javascript
globalThis.behavior = {
OnCreate() {},
Start() {},
OnEnable() {},
FixedUpdate(dt) {},
Update(dt) {},
OnDisable() {},
OnDestroy() {},
OnStop() {},
};