Playcanvas Esm Scripts


Last update

Jun 19, 2024

Updates legacy PlayCanvas scripts to the newer ESM Scripts format

This codemod transforms legacy PlayCanvas Scripts into their newer modern equivalents. You can open this codemod and run it over your existing scripts in vscode using the link to the side.

The codemod fully supports all syntax transformations apart from 'json' type attributes..

To run this codemod use

npx codemod playcanvas-esm-scripts -i "./your-file.js"

This will translate the following older Script

var Rotator = pc.createScript('rotator');
Rotator.attributes.add('speed', { type: 'number', default: 10, min: 0, max: 10 });
Rotator.prototype.update = function (dt) {
this.entity.rotateLocal(0, this.speed, 0);

transforms it into the modern ESM Scripts format

import { Script } from 'playcanvas'
export class Rotator extends Script {
* @attribute
* @type {number}
* @range [0, 10]
speed = 10;
update(dt) {
this.entity.rotateLocal(0, this.speed, 0);

It will map any attribute properties to their relevant jsdocs tags according to the spec, and export all classes in the correct format. It will also handle enums correctly.

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now