TinyScript lets you move game logic out of JSX component functions and into dedicated class instances. Each script is bound to one node, receives a typed reference to it, and can subscribe to that node’s lifecycle events — all without coupling rendering concerns to behaviour code.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sanchedev/tiny-engine/llms.txt
Use this file to discover all available pages before exploring further.
Creating a script
ExtendTinyScript and supply the PrimaryNode enum value for the node type the script will be attached to:
this.me so that property access and method calls are fully type-checked.
The setup() lifecycle method
setup() is the single lifecycle hook you must implement. It is called once when the script’s node finishes initialising. Register event listeners, set up subscriptions, and perform one-time configuration here.
this.me — typed node reference
this.me returns the node this script is attached to, typed to the PrimaryNode you declared. Accessing it before init() is called (i.e. before the node starts) throws a NodeNotInitializedError.
this.me inside setup() or inside callbacks registered in setup() — never in the constructor.
this.connect(eventName, callback) — type-safe event subscription
connect subscribes to an event on the attached node. The method is type-safe: TypeScript infers valid event names and matching callback signatures from the node type.
| Parameter | Type | Description |
|---|---|---|
eventName | keyof NodeEvents<T> | Event name string, e.g. 'started', 'destroyed', 'updated'. |
callback | Matching event function signature | Callback invoked when the event fires. |
| Event | Callback signature | Description |
|---|---|---|
'started' | () => void | Node entered the scene tree. |
'destroyed' | () => void | Node was removed from the scene tree. |
'updated' | (delta: number) => void | Called every frame with elapsed seconds. |
Full example: PlayerScript with health management
Attaching a script to a node
Pass a script instance to thescript prop on any JSX node:
script prop is accepted on every node type. The engine calls script.init(node) and then script.setup() automatically when the node starts.
Accessing a script from outside — useScript
Use the useScript hook to retrieve the script instance from a node reference. This is useful when a sibling or parent component needs to call methods on the script.
useScript returns a Reference object. Access the live script instance via .current.