add_components
Attach custom components like audio, camera, collision, or light to a specified entity in PlayCanvas Editor to enhance its functionality and behavior in real-time 3D applications.
Instructions
Add components to an entity
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| components | Yes | A dictionary that contains the components of the entity and their data. | |
| id | Yes | An entity ID. |
Implementation Reference
- extension/main.js:314-324 (handler)WebSocket server handler implementing the add components logic: retrieves entity, adds each component using entity.addComponent(name, data), logs, and returns updated entity JSON.wsc.method('entities:components:add', (id, components) => { const entity = api.entities.get(id); if (!entity) { return { error: 'Entity not found' }; } Object.entries(components).forEach(([name, data]) => { entity.addComponent(name, data); }); log(`Added components(${Object.keys(components).join(', ')}) to entity(${id})`); return { data: entity.json() }; });
- src/tools/entity.ts:84-94 (registration)MCP tool registration for 'add_components', defining input schema and proxy handler to WebSocket 'entities:components:add'.mcp.tool( 'add_components', 'Add components to an entity', { id: EntityIdSchema, components: ComponentsSchema }, ({ id, components }) => { return wss.call('entities:components:add', id, components); } );
- src/tools/schema/entity.ts:268-279 (schema)Zod schema defining the structure of components (audiolistener, camera, etc.) that can be added to an entity.export const ComponentsSchema = z.object({ audiolistener: AudioListenerSchema.optional(), camera: CameraSchema.optional(), collision: CollisionSchema.optional(), element: ElementSchema.optional(), light: LightSchema.optional(), render: RenderSchema.optional(), rigidbody: RigidBodySchema.optional(), screen: ScreenSchema.optional(), script: ScriptSchema.optional(), sound: SoundSchema.optional() }).describe('A dictionary that contains the components of the entity and their data.');
- src/tools/schema/common.ts:35-35 (schema)Zod schema for the entity ID parameter, validating as UUID string.export const EntityIdSchema = z.string().uuid().describe('An entity ID.');