PlayCanvas API Reference
Welcome to the PlayCanvas API Reference! These pages document the public interface to the PlayCanvas Engine used when scripting your PlayCanvas applications.
Before you dive into the API, you should get to know the core principles of scripting in PlayCanvas. The User Manual has a whole topic on the subject.
The pc Namespace
The API is contained within an object named
pc. We refer to this as a namespace. Any objects that you create will be defined within this namespace. For example, if you create a new 3D vector object, you would do:
var v = new pc.Vec3();
Navigating the API
The API defines many classes (shown here on the left). It’s not immediately obvious where to start! Let’s describe a PlayCanvas application and map that to some of the available classes.
Every application you create instantiates a single
pc.Application object. This object manages the lifecycle of your application: initialization, update loop and termination. When creating an app in the PlayCanvas Editor, the pc.Application is created for you but you can still access it via this.app from your scripts.
The application object exposes a number of useful properties, giving you access to input devices (
pc.GamePads), the graphics device (
pc.GraphicsDevice), the current scene (
pc.Scene) and the root entity of the scene graph (
Entities are discrete things in your application such as a character or a vehicle. The pc.Entity API is useful for transforming (positioning/rotating/scaling) entities, as well as adding and removing components.
Components grant entities extra functionality, such as audio playback, 3D model rendering and so on. For each component, there are two classes defined: a component and component system. For example, the camera component defines
pc.CameraComponentSystem. The component class defines functions and properties for individual components whereas the component system class defines functions and properties global to all components of that type. Accessing a property on a component looks something like this:
var aspect = this.entity.camera.aspectRatio;
Help Us Improve the API Reference
PlayCanvas is an open source engine and you can explore the repo on GitHub. This API Reference is generated from documentation entered directly into the source using JSDoc format. We encourage you to get involved and contribute to the project by submitting pull requests and reporting issues as and when you find them.