Create a new Entity.
Optional
name: stringThe non-unique name of the entity, default is "Untitled".
Optional
app: AppBase = ...The application the entity belongs to, default is the current application.
const entity = new pc.Entity();
// Add a Component to the Entity
entity.addComponent("camera", {
fov: 45,
nearClip: 1,
farClip: 10000
});
// Add the Entity into the scene graph
app.root.addChild(entity);
// Move the entity
entity.translate(10, 0, 0);
// Or translate it by setting its position directly
const p = entity.getPosition();
entity.setPosition(p.x + 10, p.y, p.z);
// Change the entity's rotation in local space
const e = entity.getLocalEulerAngles();
entity.setLocalEulerAngles(e.x, e.y + 90, e.z);
// Or use rotateLocal
entity.rotateLocal(0, 90, 0);
Readonly
animGets the AnimComponent attached to this entity.
Readonly
animationGets the AnimationComponent attached to this entity.
Readonly
audiolistenerGets the AudioListenerComponent attached to this entity.
Readonly
buttonGets the ButtonComponent attached to this entity.
Readonly
cameraGets the CameraComponent attached to this entity.
Readonly
collisionGets the CollisionComponent attached to this entity.
Readonly
elementGets the ElementComponent attached to this entity.
Readonly
gsplatGets the GSplatComponent attached to this entity.
Readonly
layoutchildGets the LayoutChildComponent attached to this entity.
Readonly
layoutgroupGets the LayoutGroupComponent attached to this entity.
Readonly
lightGets the LightComponent attached to this entity.
Readonly
modelGets the ModelComponent attached to this entity.
The non-unique name of a graph node. Defaults to 'Untitled'.
Readonly
particlesystemGets the ParticleSystemComponent attached to this entity.
Readonly
renderGets the RenderComponent attached to this entity.
Readonly
rigidbodyGets the RigidBodyComponent attached to this entity.
Readonly
screenGets the ScreenComponent attached to this entity.
Readonly
scriptGets the ScriptComponent attached to this entity.
Readonly
scrollbarGets the ScrollbarComponent attached to this entity.
Readonly
scrollviewGets the ScrollViewComponent attached to this entity.
Readonly
soundGets the SoundComponent attached to this entity.
Readonly
spriteGets the SpriteComponent attached to this entity.
Interface for tagging graph nodes. Tag based searches can be performed using the GraphNode#findByTag function.
Gets the enabled state of the GraphNode.
Sets the enabled state of the GraphNode. If one of the GraphNode's parents is disabled there will be no other side effects. If all the parents are enabled then the new value will activate or deactivate all the enabled children of the GraphNode.
Gets the depth of this child within the graph. Note that for performance reasons this is only recalculated when a node is added to a new parent. In other words, it is not recalculated when a node is simply removed from the graph.
Gets the path of this graph node relative to the root of the hierarchy.
Create a new component and add it to the entity. Use this to add functionality to the entity like rendering a model, playing sounds and so on.
The name of the component to add. Valid strings are:
Optional
data: objectThe initialization data for the specific component type. Refer to each specific component's API reference page for details on valid values for this parameter.
The new Component that was attached to the entity or null if there was an error.
Destroy the entity and all of its descendants. First, all of the entity's components are disabled and then removed. Then, the entity is removed from the hierarchy. This is then repeated recursively for all descendants of the entity.
The last thing the entity does is fire the destroy
event.
Search the graph node and all of its descendants for the nodes that satisfy some search criteria.
This can either be a function or a string. If it's a function, it is executed for each descendant node to test if node satisfies the search logic. Returning true from the function will include the node into the results. If it's a string then it represents the name of a field or a method of the node. If this is the name of a field then the value passed as the second argument will be checked for equality. If this is the name of a function then the return value of the function will be checked for equality against the valued passed as the second argument to this function.
Optional
value: anyIf the first argument (attr) is a property name then this value will be checked against the value of the property.
The array of graph nodes that match the search criteria.
Get the first node found in the graph by its full path in the graph. The full path has this form 'parent/child/sub-child'. The search is depth first.
The first node to be found matching the supplied path. Returns null if no node is found.
Return all graph nodes that satisfy the search query. Query can be simply a string, or comma separated strings, to have inclusive results of assets that match at least one query. A query that consists of an array of tags can be used to match graph nodes that have each tag of array.
A list of all graph nodes that match the query.
Search the entity and all of its descendants for the first component of specified type.
The name of the component type to retrieve.
A component of specified type, if the entity or any of its descendants has one. Returns undefined otherwise.
Search the entity and all of its descendants for all components of specified type.
The name of the component type to retrieve.
All components of specified type in the entity or any of its descendants. Returns empty array if none found.
Search the graph node and all of its descendants for the first node that satisfies some search criteria.
This can either be a function or a string. If it's a function, it is executed for each descendant node to test if node satisfies the search logic. Returning true from the function will result in that node being returned from findOne. If it's a string then it represents the name of a field or a method of the node. If this is the name of a field then the value passed as the second argument will be checked for equality. If this is the name of a function then the return value of the function will be checked for equality against the valued passed as the second argument to this function.
Optional
value: anyIf the first argument (attr) is a property name then this value will be checked against the value of the property.
A graph node that match the search criteria. Returns null if no node is found.
Search the entity and all of its descendants for the first script instance of specified type.
The name or type of ScriptType.
A script instance of specified type, if the entity or any of its descendants has one. Returns undefined otherwise.
Search the entity and all of its descendants for all script instances of specified type.
The name or type of ScriptType.
All script instances of specified type in the entity or any of its descendants. Returns empty array if none found.
Fire an event, all additional arguments are passed on to the event listener.
Name of event to fire.
Optional
arg1: anyFirst argument that is passed to the event handler.
Optional
arg2: anySecond argument that is passed to the event handler.
Optional
arg3: anyThird argument that is passed to the event handler.
Optional
arg4: anyFourth argument that is passed to the event handler.
Optional
arg5: anyFifth argument that is passed to the event handler.
Optional
arg6: anySixth argument that is passed to the event handler.
Optional
arg7: anySeventh argument that is passed to the event handler.
Optional
arg8: anyEighth argument that is passed to the event handler.
Self for chaining.
Executes a provided function once on this graph node and all of its descendants.
The function to execute on the graph node and each descendant.
Optional
thisArg: objectOptional value to use as this when executing callback function.
Get the world space rotation for the specified GraphNode in Euler angle form. The rotation is returned as euler angles in a Vec3. The value returned by this function should be considered read-only. In order to set the world space rotation of the graph node, use GraphNode#setEulerAngles.
The world space rotation of the graph node in Euler angle form.
Get the rotation in local space for the specified GraphNode. The rotation is returned as euler angles in a Vec3. The returned vector should be considered read-only. To update the local rotation, use GraphNode#setLocalEulerAngles.
The local space rotation of the graph node as euler angles in XYZ order.
Get the position in local space for the specified GraphNode. The position is returned as a Vec3. The returned vector should be considered read-only. To update the local position, use GraphNode#setLocalPosition.
The local space position of the graph node.
Get the rotation in local space for the specified GraphNode. The rotation is returned as a Quat. The returned quaternion should be considered read-only. To update the local rotation, use GraphNode#setLocalRotation.
The local space rotation of the graph node as a quaternion.
Get the scale in local space for the specified GraphNode. The scale is returned as a Vec3. The returned vector should be considered read-only. To update the local scale, use GraphNode#setLocalScale.
The local space scale of the graph node.
Get the world space position for the specified GraphNode. The position is returned as a Vec3. The value returned by this function should be considered read-only. In order to set the world space position of the graph node, use GraphNode#setPosition.
The world space position of the graph node.
Get the world space rotation for the specified GraphNode. The rotation is returned as a Quat. The value returned by this function should be considered read-only. In order to set the world space rotation of the graph node, use GraphNode#setRotation.
The world space rotation of the graph node as a quaternion.
Insert a new child to the child list at the specified index and update the parent value of the child node. If the node already had a parent, it is removed from its child list.
The new child to insert.
The index in the child list of the parent where the new node will be inserted.
Reorients the graph node so that the negative z-axis points towards the target. This function has two valid signatures. Either pass 3D vectors for the look at coordinate and up vector, or pass numbers to represent the vectors.
If passing a 3D vector, this is the world space coordinate to look at. Otherwise, it is the x-component of the world space coordinate to look at.
Optional
y: number | Vec3If passing a 3D vector, this is the world space up vector for look at transform. Otherwise, it is the y-component of the world space coordinate to look at.
Optional
z: numberZ-component of the world space coordinate to look at.
Optional
ux: number = 0X-component of the up vector for the look at transform. Defaults to 0.
Optional
uy: number = 1Y-component of the up vector for the look at transform. Defaults to 1.
Optional
uz: number = 0Z-component of the up vector for the look at transform. Defaults to 0.
// Look at another entity, using the (default) positive y-axis for up
const position = otherEntity.getPosition();
this.entity.lookAt(position);
// Look at another entity, using the negative world y-axis for up
const position = otherEntity.getPosition();
this.entity.lookAt(position, pc.Vec3.DOWN);
Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.
Optional
name: stringName of the event to unbind.
Optional
callback: HandleEventCallbackFunction to be unbound.
Optional
scope: objectScope that was used as the this when the event is fired.
Self for chaining.
const handler = function () {
};
obj.on('test', handler);
obj.off(); // Removes all events
obj.off('test'); // Removes all events called 'test'
obj.off('test', handler); // Removes all handler functions, called 'test'
obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
Attach an event handler to an event.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
Can be used for removing event in the future.
Attach an event handler to an event. This handler will be removed after being fired once.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
Rotates the graph node in world space by the specified Euler angles. Eulers are specified in degrees in XYZ order. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the world space rotation.
3-dimensional vector holding world space rotation or rotation around world space x-axis in degrees.
Optional
y: numberRotation around world space y-axis in degrees.
Optional
z: numberRotation around world space z-axis in degrees.
Rotates the graph node in local space by the specified Euler angles. Eulers are specified in degrees in XYZ order. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the local space rotation.
3-dimensional vector holding local space rotation or rotation around local space x-axis in degrees.
Optional
y: numberRotation around local space y-axis in degrees.
Optional
z: numberRotation around local space z-axis in degrees.
Sets the world space rotation of the specified graph node using euler angles. Eulers are interpreted in XYZ order. Eulers must be specified in degrees. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the world space euler rotation.
3-dimensional vector holding eulers or rotation around world space x-axis in degrees.
Optional
y: numberRotation around world space y-axis in degrees.
Optional
z: numberRotation around world space z-axis in degrees.
Sets the local space rotation of the specified graph node using euler angles. Eulers are interpreted in XYZ order. Eulers must be specified in degrees. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the local space euler rotation.
3-dimensional vector holding eulers or rotation around local space x-axis in degrees.
Optional
y: numberRotation around local space y-axis in degrees.
Optional
z: numberRotation around local space z-axis in degrees.
Sets the local space position of the specified graph node. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the local space position.
3-dimensional vector holding local space position or x-coordinate of local space position.
Optional
y: numberY-coordinate of local space position.
Optional
z: numberZ-coordinate of local space position.
Sets the local space rotation of the specified graph node. This function has two valid signatures: you can either pass a quaternion or 3 numbers to specify the local space rotation.
Quaternion holding local space rotation or x-component of local space quaternion rotation.
Optional
y: numberY-component of local space quaternion rotation.
Optional
z: numberZ-component of local space quaternion rotation.
Optional
w: numberW-component of local space quaternion rotation.
Sets the local space scale factor of the specified graph node. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the local space scale.
3-dimensional vector holding local space scale or x-coordinate of local space scale.
Optional
y: numberY-coordinate of local space scale.
Optional
z: numberZ-coordinate of local space scale.
Sets the world space position of the specified graph node. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the world space position.
3-dimensional vector holding world space position or x-coordinate of world space position.
Optional
y: numberY-coordinate of world space position.
Optional
z: numberZ-coordinate of world space position.
Sets the world space rotation of the specified graph node. This function has two valid signatures: you can either pass a quaternion or 3 numbers to specify the world space rotation.
Quaternion holding world space rotation or x-component of world space quaternion rotation.
Optional
y: numberY-component of world space quaternion rotation.
Optional
z: numberZ-component of world space quaternion rotation.
Optional
w: numberW-component of world space quaternion rotation.
Translates the graph node in world space by the specified translation vector. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the world space translation.
3-dimensional vector holding world space translation or x-coordinate of world space translation.
Optional
y: numberY-coordinate of world space translation.
Optional
z: numberZ-coordinate of world space translation.
Translates the graph node in local space by the specified translation vector. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the local space translation.
3-dimensional vector holding local space translation or x-coordinate of local space translation.
Optional
y: numberY-coordinate of local space translation.
Optional
z: numberZ-coordinate of local space translation.
The Entity is the core primitive of a PlayCanvas game. Generally speaking an object in your game will consist of an Entity, and a set of Components which are managed by their respective ComponentSystems. One of those components maybe a ScriptComponent which allows you to write custom code to attach to your Entity.
The Entity uniquely identifies the object and also provides a transform for position and orientation which it inherits from GraphNode so can be added into the scene graph. The Component and ComponentSystem provide the logic to give an Entity a specific type of behavior. e.g. the ability to render a model or play a sound. Components are specific to an instance of an Entity and are attached (e.g.
this.entity.model
) ComponentSystems allow access to all Entities and Components and are attached to the AppBase.