Help in setting up VS code for playcanvas

I am facing a lot of issues with the playcanvas vs code extension because it does not show errors until the parse the scripts and run the game. As in, the type checking, code suggestions, line completion suggestions dont work. I am not entirely sure if the problem is because of vs code or the playcanvas extension

one of such instances is the below image. isDrawing boolean in Initialize is commented, yet the isDrawing boolean in the Update does not show the red underline indicating error.

@KPal

Hi @thoast,

I’m a little confused by the example provided here. In this case, you commented out this.isDrawing = false, meaning that most likely this.isDrawing = undefined which is a falsy value.

In your update function you then check to see if this.isDrawing is truthy, which it wouldn’t be because it is presumably undefined, meaning that the call to draw the arrow would never be processed. Regarding the lint highlighting, since it’s just Javascript and not Typescript, would we expect to see an error here when we’re just checking for truthiness? As far as I can tell, by your description of the behavior, the script is acting as intended, and the IDE as well.

Am I missing something?

Hi thoast,

Could you confirm what version of the VSCode extension you are using? Also please submit a report through the command palette (Ctrl + P, PlayCanvas: Report Issue). I will be able to track your state and debug from there.

Thanks,

KPal

Im not too sure myself.
I come for Unity and Cocos and as far as scripting in VS code, the IDE shows me the errors that i make while i code. for example,

  • ctrl+click on a function would take to the function definition
  • unused variables are highlighted and a tool tip showing that the variable is unused
  • end of line syntax suggestions
  • the suggestion to add a ‘this.’ before an existing variables
  • right click → go to definition takes me the place where the variable/function was defined

i was expected these sort of features to work with javascript within vs code, and I think it does because it does work for Python, C# and Typescript.

I am using Visual Studio Code 1.120 and PlayCanvas VS code extension 1.10.4

1 Like

Im pretty sure it must a setup issue on my side, but sure i will send the report.
I am using Visual Studio Code 1.120 and PlayCanvas VS code extension 1.10.4

1 Like

Dear thoast

Thank you I have received it and am looking into it for you now.

Regards

KPal

1 Like

Dear thoast

So for more explicit type checking in your scripts I would advise to include a jsconfig.json. Something like this would suffice:

{
    "compilerOptions": {
        "target": "es2020",
        "checkJs": true
    },
    "include": [".pc/**/*.d.ts", "**/*.js", "**/*.mjs"],
}

This will correctly type check all your files.

Regards

KPal

yes it works.. to some extent?

it doesnt help with type checking nor identified illegal code syntaxes. The same issues mentioned above

Dear thoast

Could you share some screenshots of what you are experiencing so I have some more context? Thanks!

Regards
KPal

Dear thoast

This actually shows VS Code type checking is working. The warning:

'SoundManager' is possibly 'null'. ts(18047)

comes from VS Code’s JavaScript/TypeScript checker. It happens because pc.createScript() is typed as possibly returning null, for example if a script with that name already exists.

So this screenshot is not showing missing type checking, it is showing a real type-check warning.

The earlier this.isDrawing example is a different case. In JavaScript, reading a missing property is legal:

if (this.isDrawing) {
...
}

If it was never assigned, it is just undefined, not a syntax error.

One important limitation is that classic PlayCanvas scripts are not strictly type-safe. They rely on runtime patterns like pc.createScript(), prototype assignment, and editor-injected attributes. Stronger type safety is mainly prioritised for ESM scripts, where imports, exports, classes, and JSDoc/TypeScript tooling can be understood much more reliably by VS Code.

If you have an example of invalid JavaScript syntax that VS Code is not flagging, please share that exact snippet/screenshot.

Regards
KPal

Thanks for the clarification. I think I explained the problem poorly — I’m not mainly asking about type safety or invalid syntax.

What I am looking for is IDE/editor intelligence similar to what I get in normal JS/TS projects.

For example, in PlayCanvas scripts I would expect behaviors like:

  1. Go to Definition / Ctrl+Click
    If I call a function:
this.movePlayer();

I want Ctrl+Click or Right Click → Go to Definition to take me to:

Player.prototype.movePlayer = function () {

  1. Find references
    If I rename or inspect a method/property, I want VS Code to understand where it is used.

  2. Missing this. detection
    Example:

speed = 10;

when I accidentally meant:

this.speed = 10;

In a normal JS/TS workflow, this usually gets flagged as an undefined variable or accidental global.

  1. Property autocomplete
    After typing:
this.

I would expect script properties/methods to be suggested, especially ones already assigned in the same script.

  1. Unused variable warnings
    Example:
const velocity = 10;

if never used, I would expect VS Code to warn about it.

Also, not sure if this is relevant, but I get this warning when i open the playcanvas project (Ctrl+Shift+P → PlayCanvas:Open Project)

my npm version is 11.6.2

VSCode is generally pretty poor dealing with the ES5 style scripting that PlayCanvas Editor projects tend to use.

If this is what you want, I suggest moving to ESM scripts Scripting | PlayCanvas Developer Site

thanks. i was exploring all options before migrating completely to ESM style scripting.

I was explaining the same to claude and it spat out a vs code extension that solves the exact issues mentioned above. So that has been solved, for now.

Thanks for your time