Skip to content

Adding ESM script to ScriptRegistry - not added by it's name (bug). #8824

Description

@Maksims

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions