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.
useRefNode creates a typed reference to a scene-graph node. Pass the returned NodeReference as the ref prop on a JSX node; once the node mounts, ref.node is populated with the live instance. This is the primary way to imperatively access a node’s properties and events from inside a component.
useRefNode
Signature
Parameters
The node type to reference. Must be one of the
PrimaryNode enum values. The type parameter T is inferred automatically from this argument, so ref.node is fully typed.Available values: PrimaryNode.Transform, PrimaryNode.Sprite, PrimaryNode.AnimationPlayer, PrimaryNode.Collider, PrimaryNode.RayCast, PrimaryNode.Clickable, PrimaryNode.Timer, PrimaryNode.Rectangle.Return value
NodeReference<T> — an object with a node getter that returns the live node instance. Accessing node before the node has mounted throws a NodeNotInitializedError.
Example — ref to a sprite
Player.tsx
Example — ref used with useSpawn
Arena.tsx
useChild
useChild retrieves a descendant node by path and type after the root node has started. Use it when you need a reference to a node that is deep inside the JSX tree rather than a direct child.
Signature
Parameters
An ordered array of node
id values that form the path from the component’s root node to the target. Each segment must match a node’s id prop.The expected node type at the end of the path. Throws
NodeTypeMismatchError if the found node has a different type.Example
Arena.tsx
useChild requires a single root node in the component. It throws HookRequiresNodeRootError if the component returns multiple root-level nodes. The reference is resolved when the root node fires its started event.useScript
useScript retrieves the TinyScript instance attached to a node reference. The script is available inside useMount or event callbacks — not synchronously at component setup time.
Signature
Parameters
A node reference whose
script property should be read. Create this with useRefNode.Return value
Reference<T | undefined> — a mutable ref whose .current property is the script instance once the node has mounted, or undefined before that.
Example
Player.tsx
useRef
useRef stores any mutable value that must survive across renders without triggering reactive updates. It is equivalent to a plain box with a .current property.
Signature
Parameters
The initial value to store in the reference.
Return value
Reference instance whose .current property can be read and written freely.
Example
ClickCounter.tsx