changeDispatch
Installs `_G.__zero_dispatch_asset_change`, the Luau half of the asset-type **change-callback** system. The engine calls it once per VFS source write (via `zero_scripting::ffi_callbacks::fire_asset_change_dispatch`, queued as `VfsMutation::AssetSourceWritten`).
asset_change_dispatch (module)
Installs _G.__zero_dispatch_asset_change, the Luau half of the
asset-type change-callback system. The engine calls it once per VFS
source write (via zero_scripting::ffi_callbacks::fire_asset_change_dispatch,
queued as VfsMutation::AssetSourceWritten).
What it does
- Receives the written VFS path.
- Walks up the path to the enclosing
<name>.<type>/typed-asset folder (deepest registered-type suffix wins, so the direct owner of the write is chosen for nested typed assets). - Loads that type's
<type>.assetType/behavior.luauvia@builtin::assetTypes.assetType.shared.ref.loadTypeModule. - If the module exports an
onChangefunction, callsonChange(ref, change)whererefis the typedAssetReffor the changed asset andchange = { path, asset, type }.
This is the type-level analogue of the component-centric
onAssetReload(field) fan-out: components react to assets they
reference; an asset type reacts to writes inside its own instances.
Re-entrancy
A best-effort synchronous guard suppresses dispatch for an asset while its
own onChange is running, so a handler that writes back inline doesn't
recurse immediately. It does not span asynchronous work — writes
queued during a synchronous onChange are processed on a later drain.
onChange handlers must therefore be convergent: diff the meaningful
state before acting and short-circuit when there's nothing to do (the
dynamicAsset example only regenerates when the prompt actually changed
and bails while a generation is in flight). Idempotency is the contract,
exactly as it is for services' start/stop.
Related
@builtin::assetTypes.assetType.shared.ref— ownsloadTypeModule+ the per-typerefmethod dispatch.assetTypes/assetType.assetType/template/behavior.luau— the documented template that shows how to authorref,global, andonChange.assetTypes/dynamicAsset.assetType— the reference type that usesonChangefor prompt-driven regeneration with version control.
Scoped to this part · feeds back into the world's score.