User Manual

Creating and attaching scripts

Creating a new script

To create a new script use the Asset Panel and select New Script

New Script

Attaching a script to an Entity

Script Components are attached to Entities in the same way as all other Components using the Add Component button in the Entity inspector.

Once you have added a Script Component you can specify which javascript files to load. Use the Add Script button to pick scripts from your asset panel. Or drag and drop a script from the asset panel onto the component.

If you are using the PlayCanvas code repository to store your code, you can edit code in the PlayCanvas code editor, click a script's name below the URL input box.

If you are using Github or Bitbucket you can not edit you scripts in PlayCanvas, you must make your commits through your source control system.

A script component can load multiple script files, just add multiple scripts to the component. The order in which you add your scripts on a Script Component is the order in which the scripts are going to be initialized and updated. If you want to change the order of a script, click on the Up - Down arrows next to the Script's title. To remove a script click on the X button.

Using Script Priorities

The second way to use a script in your application is to add them to the script priority list. This will load your script up front, before the rest of your application. See the Script Priorities page.