Async operations and scene exit
Check whether the component is still enabled after loading.
Commands use awaitSceneScope for this check. In a component, use awaitComponentScopeResource when the loaded resource needs to be released.
const spawned = await this.awaitComponentScopeResource(
this.node.spawnPrefab({
prefabId: this.config.prefabId,
localId: 'preview',
}),
(resource) => resource.dispose(),
);
if (!spawned) return;
spawned.node.setVisible(true);
If the component has been disabled, the method releases the prefab and returns undefined.
Owner is activeOperation completes → use the result
Owner has been removedOperation completes → release the resource → skip the rest
For cancellable requests, a service receives ctx.signal: after await, check ctx.signal?.throwIfAborted() before applying the result. Cancellation cannot forcibly stop an arbitrary Promise.
ownDisposer registers synchronous cleanup until the component is removed; scopeSignal lasts until detach. Disabling a component does not end this lifetime. Call super.onDetach() from an overridden onDetach so the SDK aborts the signal and releases registered resources.