User Manual

Code Editor

Script assets are edited using PlayCanvas' Code Editor. Double click on a script asset to open the file in the Editor. The Editor supports real-time collaborative editing by all users with permission to edit the code. You will see other user's avatars in the bottom right of the code editor window

Code Editor

Collaboration, Saving & Reverting

The code editor is collaborative which means that every user who has the document open in the editor will see changes as they are made by other developers. However, changes are not saved automatically and when the application is run from the Editor the saved version is loaded. This means you can choose at which point to commit your change to be used by the application. Any user can save the document at any time. The Revert button will restore the document back to the last saved version. If all users exit the document before saving the unsaved changes will be preserved for a short time before the document is automatically reverted to the saved version. So you should save your work before exiting the document.

Hot Keys

The editor is based on CodeMirror and the full list of hot keys can be found in their documentation. The most common can be found below:

UndoCtrl + ZCmd + Z
RedoCtrl + YCmd + Shift + Z or Cmd + Y
Find in fileCtrl + FCmd + F
Find next matchCtrl + GCmd + G
Find previous matchCtrl + Shift + GCmd + Shift + G
ReplaceCtrl + Shift + FCmd + Alt + F
Replace allCtrl + Shift + RCmd + Shift + Alt + F
Rename variableCtrl + QCtrl + Q
Comment line or selectionCtrl + /Cmd + /
Indent line or selectionCtrl + [Cmd + [
Un-Indent line or selectionCtrl + ]Cmd + ]
Auto indent line or selectionCtrl + ICmd + I
Jump to declarationAlt + .Alt + .
Show autocompleteCtrl + SpaceCtrl + Space
Show documentationCtrl + OCmd + O

Extra Tips

Quick Searching

Highlighting a word in the code editor will highlight all other matches in the file which makes it easier to check where a variable or function is being used.

Quick Searching

Use Regex for Searching

By default, the search feature is case insensitive and matches any part of a word. Regular expressions (regex) can be used to make more specific matches.

Example Regex

Common regex patterns are (using the word 'position' for all examples):

Case sensitive/position/Matches 'position' and 'getposition'. Doesn't match 'Position' or 'getPosition'.
Case insensitive/position/iMatches 'position', 'getposition', 'Position' and 'getPosition'.
Whole word (case sensitive)/\bposition\b/Matches 'position'. Doesn't match 'Position' or 'getPosition'.
Whole word (case insensitive)/\bposition\b/iMatches 'position' and 'Position'. Doesn't match 'getPosition'.

If you would like to learn and experiment more with regex, then RegExr is great site with cheatsheets, examples and an online editor for testing regex expressions.

Multiple Selection Editing

Holding down Ctrl (PC) or Cmd (Mac) and clicking left mouse button will add another cursor to the editor. This allows you to quickly make the same changes in multiple areas of the file.

Multple Selection Editing

Rectangular Selection

Holding down Alt and dragging left mouse button will create a rectangular selection which is useful for selecting and editing columns of text.

Rectangular Selection

This site is translated by the community. If you want to get involved visit this page