Script Attribute: add 'script' type?

I’ve had a search around and can’t find anything on this, but apologies if it’s been covered before.

Is it possible to have a script type for ScriptAttributes args.type? Something like:

MyScript.attributes.add('entityWithScript', {
    type: 'script',
    scriptType: 'otherScript'
});

Where otherScript would be an existing registered script name.

This would let developers reference an entity that has a certain script, instead of just an entity which may or may not have a required script (via the entity type), making scripts more reusable between entities by becoming more generic.

// Can be called knowing this.entityWithScript will have `otherScript`

this.entityWithScript.script.otherScript.doSomething()

Maybe the this.entityWithScript reference could be shorthand for reaching into the other entities script.otherScript component.

This could perhaps go for the asset type too, where the attribute requires a template that has a certain script attached.

Damn, found it after posting. https://github.com/playcanvas/editor/issues/361

hey @_Undefined you mind me asking how u did this?

This is a request forum, I wasn’t asking for support. It won’t be possible until Be able to add restrictions on what components or scriptTypes an Entity must have to be referenced · Issue #361 · playcanvas/editor · GitHub is implemented.

1 Like