Executing ESM scripts directly within the PlayCanvas Editor viewport

Hi everyone,
I’m working on a project using the new ESM modules. I would like to know if there is a way to have these scripts execute directly inside the Editor’s viewport, allowing me to see logic or visual changes in real-time without launching the game.

Specifically:

  • How can I correctly import/structure an ESM module so the Editor treats it as an “editor script”?
  • Is there a specific pattern to enable update loops or custom functions to run while in edit mode?

Thanks for any insights!

1 Like

I did this before with none mjs scripts so perhaps you can try it / fork it to make it work with mjs files?

1 Like

Thanks for the reply. To clarify: my tool already preloads and executes standard .js scripts correctly within the Editor. The problem is specifically with .mjs (ESM) modules.

The main issues I’m facing are:

  • DOM Injection: When I try to inject .mjs files into the DOM, they don’t play well with PlayCanvas’s internal loading system.

  • Registration: Even if the import finishes, the scripts are not being registered correctly in the Editor’s registry.

  • Attribute Hydration: Because they aren’t registered properly, the attributes don’t show up in the Inspector and the data isn’t ‘hydrated’ (synced) with the entities.

Essentially, I can get the file into the browser, but I can’t get the Editor to recognize it as a functional script component.