Skip to main content

Scripting

Scripts are how you give entities behavior. In the Editor, a script is an asset like any other: you create it in the Assets panel, attach it to an entity with a Script component, and tune its attributes in the Inspector without touching the code. This section covers those Editor tools.

Learn the Basics First

New to scripting in PlayCanvas? Start with Scripting in Common Topics, which covers what a script can do: its lifecycle, attributes, events and the Engine it talks to. Everything there applies to scripts in Editor projects.

The Editor supports two kinds of script. ESM scripts are ECMAScript modules (.mjs files) that can import from each other and from packages, and they're recommended for new projects. Classic scripts (.js files) are the older format, and still work. When you create a script, its name decides the kind: end it in .mjs for an ESM script. See ESM Scripts.

In This Section​

PageWhat it covers
Managing Your ScriptsCreate, import, organize and delete scripts, and attach them to entities.
Code EditorThe Editor's built-in, collaborative code editor.
VS Code ExtensionEdit your project's scripts in Visual Studio Code, kept in sync with the Editor.
Hot ReloadingUpdate a running app with your code changes, without reloading it.
Import MapsGive ESM imports short names, or load packages from a content delivery network (CDN).
Script Loading OrderThe order scripts load in, and how publishing combines them.
Loading ScenesSwitch scenes, or load several at once, while your app runs.
AI

When a script change also needs Editor setup, use an AI coding assistant with VS Code Extension Pull/Push mode for source edits and the Editor MCP Server for attachments, attributes, instances, and Launcher verification. Review both source and Editor changes.