Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/framework/components/script/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,12 @@ class ScriptComponent extends Component {
return;
}

// Fetch schema and warn if it doesn't exist
// Fetch schema and warn if it doesn't exist. Without one there is nothing to assign
// the data against, so there is no point in carrying on
const schema = this.system.app.scripts?.getSchema(name);
if (!schema) {
Debug.warnOnce(`No schema exists for the script '${name}'. A schema must exist for data to be instantiated on the script.`);
return;
}

// Assign the attributes to the script instance based on the attribute schema
Expand Down
17 changes: 17 additions & 0 deletions test/framework/components/script/component.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3341,6 +3341,23 @@ describe('ScriptComponent', function () {
expect(a.script._scriptsIndex.undefined).to.equal(undefined);
});

it('does not throw when an ESM script has attribute data but no schema', function () {
class NoSchemaScript extends Script {
static scriptName = 'noSchemaScript';
}

const e = new Entity();
e.addComponent('script', { enabled: true });
app.root.addChild(e);

expect(() => e.script.create(NoSchemaScript, { attributes: { speed: 42 } })).to.not.throw();
expect(e.script.noSchemaScript).to.exist;
expect(e.script.noSchemaScript.speed).to.not.exist;
expect(Debug._loggedMessages.has(
'No schema exists for the script \'noSchemaScript\'. A schema must exist for data to be instantiated on the script.'
)).to.equal(true);
});

it('does not warn when a ScriptType is used', function () {
Debug._loggedMessages.clear();
createScript('nullScript');
Expand Down