# How to clear ALL scripts from an entity in code?

**URL:** <https://forum.playcanvas.com/t/how-to-clear-all-scripts-from-an-entity-in-code/31439>\
**Category:** Help & Support\
**Created:** [May 23, 2023, 11:58am UTC](https://forum.playcanvas.com/t/how-to-clear-all-scripts-from-an-entity-in-code/31439 "2023-05-23T11:58:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grimmy](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/grimmy/32/4776_2.png) [@Grimmy](https://forum.playcanvas.com/u/Grimmy)\
**Post date:** [May 23, 2023, 11:58am UTC](https://forum.playcanvas.com/t/how-to-clear-all-scripts-from-an-entity-in-code/31439/1 "2023-05-23T11:58:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [May 23, 2023, 12:11pm UTC](https://forum.playcanvas.com/t/how-to-clear-all-scripts-from-an-entity-in-code/31439/2 "2023-05-23T12:11:56Z")

</div>

Hi @Grimmy,

There is a `scripts` property under the .script component:

> **[ScriptComponent | PlayCanvas API Reference](https://api.playcanvas.com/classes/Engine.ScriptComponent.html#scripts)**
>
> Combined API reference manual for PlayCanvas

Though I’m not sure how to grab the script type name from there. Internally the engine does something like this using private API:

```javascript
// 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:

```javascript
this.entity.removeComponent("script");
this.entity.addComponent("script");

```
