OnBeforeObjectUpdate
Creates an event that fires before a Mesh|Sprite is updated. It must be declared inside a `Fn()` so the event is bound to the TSL function stack. The callback typically updates JS-side values that feed the node graph.
Core Advantages
Provides a per-object, per-frame lifecycle hook directly from TSL context. No manual three.js event wiring or teardown is needed, enabling small, predictable side effects that coordinate with node materials.
Common Uses
Advance a scriptableValue/uniform just before each object update to drive mixes or thresholds.
Write object-dependent state into Var/buffer nodes (e.g., based on world transform or instance index).
Prepare inputs or switch material node branches per object per frame.
How to adjust
Call it only inside a `Fn()` so it is pushed to the current function stack. You can register multiple hooks in the same `Fn()`. Keep the callback lightweight; avoid allocations. To disable, remove the surrounding `Fn()` build or dispose the material/object. Applies to Mesh and Sprite only.
Code Examples
1// Bind inside Fn(): advance a script value before each object update
2const pulse = scriptableValue( 0.0 );
3
4Fn(() => {
5 OnBeforeObjectUpdate(() => {
6 pulse.value = ( pulse.value + 0.02 ) % 1.0; // advance per-object per-frame
7 });
8
9 // Use pulse as a blend factor
10 material.colorNode = mix( color(0x1976d2), color(0xffc107), pulse );
11}).once();