MCPcopy Create free account
hub / github.com/esengine/esengine / getComponent

Method getComponent

packages/core/src/ECS/Entity.ts:517–530  ·  view source on GitHub ↗

* @zh 获取指定类型的组件 * @en Get component of specified type * * @param type - @zh 组件类型构造函数 @en Component type constructor * @returns @zh 组件实例,如果不存在则返回null @en Component instance, or null if not found * * @example * ```typescript * const position = entity.getComponen

(type: ComponentType<T>)

Source from the content-addressed store, hash-verified

515 * ```
516 */
517 public getComponent<T extends Component>(type: ComponentType<T>): T | null {
518 // 快速检查:位掩码
519 if (!this.hasComponent(type)) {
520 return null;
521 }
522
523 // 从Scene存储获取
524 if (!this.scene?.componentStorageManager) {
525 return null;
526 }
527
528 const component = this.scene.componentStorageManager.getComponent(this.id, type);
529 return component as T | null;
530 }
531
532 /**
533 * @zh 检查实体是否拥有指定类型的组件

Callers 15

getOrCreateComponentMethod · 0.95
removeComponentByTypeMethod · 0.95
deserializeMethod · 0.95
processMethod · 0.45
processMethod · 0.45
_createCollidersMethod · 0.45
_removeCollidersMethod · 0.45
processMethod · 0.45
onDestroyMethod · 0.45
TilesetPanelFunction · 0.45

Calls 1

hasComponentMethod · 0.95

Tested by

no test coverage detected