OnObjectUpdate
Registers a per-object callback that runs every time a Mesh or Sprite using the current material is rendered. The callback receives the current frame object (e.g., object, material, camera, renderer, deltaTime). Must be declared inside a TSL Fn() so it can be attached to the node stack.
Core Advantages
Zero-boilerplate, frame-accurate hooks tied to the render pipeline. Ideal for driving object-scoped data (via userData or other JS-side state) without writing your own render loop plumbing.
Common Uses
Drive per-object animation state (e.g., a blink phase stored in userData).
Update object-scoped caches before shading (bounds, toggles, tags).
Coordinate one-off logic when a specific object is drawn.
How to adjust
Put only light, side-effectful JS work in the callback (mutate JS values like userData or scriptableValue). Do not allocate nodes there. Ensure it’s declared inside Fn(); otherwise it won’t be bound.
Code Examples
1// Inside a TSL Fn()
2const graph = Fn(() => {
3 // Advance a per-object blink phase and expose it to the shader via userData
4 OnObjectUpdate((frame) => {
5 const obj = frame.object;
6 obj.userData.blink = (obj.userData.blink ?? 0) + frame.deltaTime;
7 });
8
9 // Read it in the graph
10 const blink = userData('blink', 'float').sin().abs();
11 material.emissiveNode = color(0x00ffff).mul(blink);
12});