# Script

The Script Component enables an entity to run user-supplied scripts. In this way, the user can write scripts (using JavaScript or TypeScript) that run when the entity is instantiated and updated on a per-frame basis.

[Image: Script Component]

## Adding Scripts

To create a new script, click on the **Add Script** dropdown in the Script Component and either:

- Select an existing script from the list
- Type a new script name and click **Create Script** to create a new script asset

Alternatively, you can drag a script asset from the Assets Panel onto the Script Component.

[Image: Add Script Dialog]

## Script Panel Controls

Each script added to the component displays as a collapsible panel with the following controls:

| Control      | Description |
|--------------|-------------|
| Script Name  | Click to select the script asset in the Assets Panel. |
| On/Off       | Toggle to enable or disable this individual script. |
| Edit         | Opens the script in the Code Editor. |
| Parse        | Re-parses the script to update its attributes. Use after modifying script attribute definitions. |
| Remove       | Removes the script from the component (click the X button). |

:::note

The **Script Name** shown here is the script's *registered name*, defined in code by `static scriptName` for [ESM scripts](https://developer.playcanvas.com/user-manual/scripting/esm-scripts.md) or by the argument to `pc.createScript('name')` for classic scripts. This is independent of the script asset's file name, so the two can differ — for example, a file named `annotation-manager.mjs` might register its script as `annotationManager`.

:::

## Script Ordering

When multiple scripts are attached to an entity, their order matters. Scripts are executed from top to bottom. You can reorder scripts by dragging and dropping them within the component.

## Script Attributes

Scripts can define custom attributes that appear in the Inspector. These attributes allow you to configure script behavior without modifying the code. Supported attribute types include:

- **boolean** - Checkbox
- **number** - Numeric input (with optional slider for min/max range)
- **string** - Text input
- **vec2**, **vec3**, **vec4** - Vector inputs
- **rgb**, **rgba** - Color picker
- **asset** - Asset picker
- **entity** - Entity picker
- **curve** - Curve editor
- **json** - Complex nested objects

See the [Script Attributes](https://developer.playcanvas.com/user-manual/scripting/script-attributes.md) documentation for details on defining attributes in your scripts.

## See Also

- [Scripting](https://developer.playcanvas.com/user-manual/scripting.md) - Learn how to write scripts
- [Editor Scripting](https://developer.playcanvas.com/user-manual/editor/scripting.md) - Managing scripts in the Editor

## Scripting Interface

The Script Component's scripting interface is [here](https://api.playcanvas.com/engine/classes/ScriptComponent.html).
