Using engine-only.
Creating ESM scripts through extending Script class.
User Manual explains how to define script, but no mention on how to add it to registry.
import { Script } from 'playcanvas';
export class Test extends Script {
static scriptName = 'test';
update(dt) {
this.entity.rotate(10 * dt, 10 * dt, 10 * dt);
}
}
API docs for ScriptRegistry have add method, which works perfect on ScriptType (non ESM scripts). But when adding ESM script using such method, then adding script to entity using script name does not work.
static scriptName seems to be ignored when adding to registry.
So this code will not result in script added:
entity.addComponent('script');
entity.script.create('test');
As well as instantiating entities from templates or any other procedural load.
It is only possible to add script to entity by class reference, which is highly limiting and prevents async loading of scripts in any form.
This is a regression in async capabilities of engine for scripting.
Solution:
When adding ESM script to registry, ensure it is registered by its static name.
Using engine-only.
Creating ESM scripts through extending Script class.
User Manual explains how to define script, but no mention on how to add it to registry.
API docs for ScriptRegistry have
addmethod, which works perfect on ScriptType (non ESM scripts). But when adding ESM script using such method, then adding script to entity using script name does not work.static scriptNameseems to be ignored when adding to registry.So this code will not result in script added:
As well as instantiating entities from templates or any other procedural load.
It is only possible to add script to entity by class reference, which is highly limiting and prevents async loading of scripts in any form.
This is a regression in async capabilities of engine for scripting.
Solution:
When adding ESM script to registry, ensure it is registered by its static name.