this.entity.script.destroy(name)
is fine if you know the name of the script. But what If I need to just remove every single script from an entity no matter what its called. How do I do that?
CHeers
this.entity.script.destroy(name)
is fine if you know the name of the script. But what If I need to just remove every single script from an entity no matter what its called. How do I do that?
CHeers
Hi @Grimmy,
There is a scripts
property under the .script component:
https://developer.playcanvas.com/en/api/pc.ScriptComponent.html#scripts
Though I’m not sure how to grab the script type name from there. Internally the engine does something like this using private API:
// destroy all scripts
for (let i = 0; i < this.entity.script.scripts.length; i++) {
const script = this.entity.script.scripts[i];
if (!script) continue;
this.entity.script.destroy(script.__scriptType.__name);
}
I think you could instead remove the script component altogether and re-create it:
this.entity.removeComponent("script");
this.entity.addComponent("script");